<chapter id="RecentDocuments">
<title>Recently Used Documents</title>
<xi:include href="xml/gtkrecentmanager.xml" />
- <xi:include href="xml/gtkrecentchooser.xml" />
- <xi:include href="xml/gtkrecentchooserdialog.xml" />
- <xi:include href="xml/gtkrecentchoosermenu.xml" />
- <xi:include href="xml/gtkrecentchooserwidget.xml" />
- <xi:include href="xml/gtkrecentfilter.xml" />
</chapter>
<chapter id="ApplicationChoosing">
GtkRangePrivate
</SECTION>
-<SECTION>
-<FILE>gtkrecentchooser</FILE>
-<TITLE>GtkRecentChooser</TITLE>
-GtkRecentChooser
-GtkRecentChooserIface
-GTK_RECENT_CHOOSER_ERROR
-GtkRecentChooserError
-gtk_recent_chooser_set_show_private
-gtk_recent_chooser_get_show_private
-gtk_recent_chooser_set_show_not_found
-gtk_recent_chooser_get_show_not_found
-gtk_recent_chooser_set_show_icons
-gtk_recent_chooser_get_show_icons
-gtk_recent_chooser_set_select_multiple
-gtk_recent_chooser_get_select_multiple
-gtk_recent_chooser_set_local_only
-gtk_recent_chooser_get_local_only
-gtk_recent_chooser_set_limit
-gtk_recent_chooser_get_limit
-gtk_recent_chooser_set_show_tips
-gtk_recent_chooser_get_show_tips
-GtkRecentSortType
-gtk_recent_chooser_set_sort_type
-gtk_recent_chooser_get_sort_type
-GtkRecentSortFunc
-gtk_recent_chooser_set_sort_func
-gtk_recent_chooser_set_current_uri
-gtk_recent_chooser_get_current_uri
-gtk_recent_chooser_get_current_item
-gtk_recent_chooser_select_uri
-gtk_recent_chooser_unselect_uri
-gtk_recent_chooser_select_all
-gtk_recent_chooser_unselect_all
-gtk_recent_chooser_get_items
-gtk_recent_chooser_get_uris
-gtk_recent_chooser_add_filter
-gtk_recent_chooser_remove_filter
-gtk_recent_chooser_list_filters
-gtk_recent_chooser_set_filter
-gtk_recent_chooser_get_filter
-<SUBSECTION Standard>
-GTK_RECENT_CHOOSER
-GTK_IS_RECENT_CHOOSER
-GTK_TYPE_RECENT_CHOOSER
-GTK_RECENT_CHOOSER_GET_IFACE
-<SUBSECTION Private>
-gtk_recent_chooser_get_type
-gtk_recent_chooser_error_quark
-</SECTION>
-
-<SECTION>
-<FILE>gtkrecentchooserdialog</FILE>
-<TITLE>GtkRecentChooserDialog</TITLE>
-GtkRecentChooserDialog
-gtk_recent_chooser_dialog_new
-gtk_recent_chooser_dialog_new_for_manager
-<SUBSECTION Standard>
-GTK_RECENT_CHOOSER_DIALOG
-GTK_IS_RECENT_CHOOSER_DIALOG
-GTK_TYPE_RECENT_CHOOSER_DIALOG
-GTK_RECENT_CHOOSER_DIALOG_CLASS
-GTK_IS_RECENT_CHOOSER_DIALOG_CLASS
-GTK_RECENT_CHOOSER_DIALOG_GET_CLASS
-
-<SUBSECTION Private>
-gtk_recent_chooser_dialog_get_type
-GtkRecentChooserDialogPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkrecentchoosermenu</FILE>
-<TITLE>GtkRecentChooserMenu</TITLE>
-GtkRecentChooserMenu
-gtk_recent_chooser_menu_new
-gtk_recent_chooser_menu_new_for_manager
-gtk_recent_chooser_menu_get_show_numbers
-gtk_recent_chooser_menu_set_show_numbers
-<SUBSECTION Standard>
-GTK_RECENT_CHOOSER_MENU
-GTK_IS_RECENT_CHOOSER_MENU
-GTK_TYPE_RECENT_CHOOSER_MENU
-GTK_RECENT_CHOOSER_MENU_CLASS
-GTK_IS_RECENT_CHOOSER_MENU_CLASS
-GTK_RECENT_CHOOSER_MENU_GET_CLASS
-
-<SUBSECTION Private>
-gtk_recent_chooser_menu_get_type
-GtkRecentChooserMenuPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkrecentchooserwidget</FILE>
-<TITLE>GtkRecentChooserWidget</TITLE>
-GtkRecentChooserWidget
-gtk_recent_chooser_widget_new
-gtk_recent_chooser_widget_new_for_manager
-<SUBSECTION Standard>
-GTK_RECENT_CHOOSER_WIDGET
-GTK_IS_RECENT_CHOOSER_WIDGET
-GTK_TYPE_RECENT_CHOOSER_WIDGET
-GTK_RECENT_CHOOSER_WIDGET_CLASS
-GTK_IS_RECENT_CHOOSER_WIDGET_CLASS
-GTK_RECENT_CHOOSER_WIDGET_GET_CLASS
-
-<SUBSECTION Private>
-gtk_recent_chooser_widget_get_type
-GtkRecentChooserWidgetPrivate
-</SECTION>
-
-<SECTION>
-<FILE>gtkrecentfilter</FILE>
-<TITLE>GtkRecentFilter</TITLE>
-GtkRecentFilter
-GtkRecentFilterInfo
-GtkRecentFilterFlags
-GtkRecentFilterFunc
-gtk_recent_filter_new
-gtk_recent_filter_get_name
-gtk_recent_filter_set_name
-gtk_recent_filter_add_mime_type
-gtk_recent_filter_add_pattern
-gtk_recent_filter_add_pixbuf_formats
-gtk_recent_filter_add_application
-gtk_recent_filter_add_group
-gtk_recent_filter_add_age
-gtk_recent_filter_add_custom
-gtk_recent_filter_get_needed
-gtk_recent_filter_filter
-<SUBSECTION Standard>
-GTK_RECENT_FILTER
-GTK_IS_RECENT_FILTER
-GTK_TYPE_RECENT_FILTER
-
-<SUBSECTION Private>
-gtk_recent_filter_get_type
-</SECTION>
-
<SECTION>
<FILE>gtkrecentmanager</FILE>
<TITLE>GtkRecentManager</TITLE>
'images/printdialog.png',
'images/progressbar.png',
'images/radio-group.png',
- 'images/recentchooserdialog.png',
'images/right-center.png',
'images/right-end.png',
'images/right-start.png',
<link linkend="GtkFileChooserDialog">
<inlinegraphic fileref="filechooser.png" format="PNG"></inlinegraphic>
</link>
- <link linkend="GtkRecentChooserDialog">
- <inlinegraphic fileref="recentchooserdialog.png" format="PNG"></inlinegraphic>
- </link>
<link linkend="GtkFontChooserDialog">
<inlinegraphic fileref="fontchooser.png" format="PNG"></inlinegraphic>
</link>
return info;
}
-static WidgetInfo *
-create_recent_chooser_dialog (void)
-{
- WidgetInfo *info;
- GtkWidget *widget;
-
- widget = gtk_recent_chooser_dialog_new ("Recent Chooser Dialog",
- NULL,
- "Cancel", GTK_RESPONSE_CANCEL,
- "Open", GTK_RESPONSE_ACCEPT,
- NULL);
- gtk_window_set_default_size (GTK_WINDOW (widget), 505, 305);
-
- info = new_widget_info ("recentchooserdialog", widget, ASIS);
- info->include_decorations = TRUE;
-
- return info;
-}
-
static WidgetInfo *
create_text_view (void)
{
retval = g_list_prepend (retval, create_window ());
retval = g_list_prepend (retval, create_filesel ());
retval = g_list_prepend (retval, create_assistant ());
- retval = g_list_prepend (retval, create_recent_chooser_dialog ());
retval = g_list_prepend (retval, create_page_setup_dialog ());
retval = g_list_prepend (retval, create_print_dialog ());
retval = g_list_prepend (retval, create_volume_button ());
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRadioMenuItem, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRadioToolButton, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRange, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentChooser, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentChooserDialog, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentChooserMenu, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentChooserWidget, g_object_unref)
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentFilter, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRecentManager, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRevealer, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkScale, g_object_unref)
#include <gtk/gtkradiomenuitem.h>
#include <gtk/gtkradiotoolbutton.h>
#include <gtk/gtkrange.h>
-#include <gtk/gtkrecentchooser.h>
-#include <gtk/gtkrecentchooserdialog.h>
-#include <gtk/gtkrecentchoosermenu.h>
-#include <gtk/gtkrecentchooserwidget.h>
-#include <gtk/gtkrecentfilter.h>
#include <gtk/gtkrecentmanager.h>
#include <gtk/gtkrender.h>
#include <gtk/gtkrevealer.h>
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooser.c - Abstract interface for recent file selectors GUIs
- *
- * Copyright (C) 2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtkrecentchooser.h"
-#include "gtkrecentchooserprivate.h"
-#include "gtkrecentmanager.h"
-#include "gtkintl.h"
-#include "gtktypebuiltins.h"
-#include "gtkprivate.h"
-#include "gtkmarshalers.h"
-
-/**
- * SECTION:gtkrecentchooser
- * @Short_description: Interface implemented by widgets displaying recently
- * used files
- * @Title: GtkRecentChooser
- * @See_also: #GtkRecentManager, #GtkRecentChooserDialog,
- * #GtkRecentChooserWidget, #GtkRecentChooserMenu
- *
- * #GtkRecentChooser is an interface that can be implemented by widgets
- * displaying the list of recently used files. In GTK+, the main objects
- * that implement this interface are #GtkRecentChooserWidget,
- * #GtkRecentChooserDialog and #GtkRecentChooserMenu.
- *
- * Recently used files are supported since GTK+ 2.10.
- */
-
-
-enum
-{
- ITEM_ACTIVATED,
- SELECTION_CHANGED,
-
- LAST_SIGNAL
-};
-
-static guint chooser_signals[LAST_SIGNAL] = { 0, };
-
-
-typedef GtkRecentChooserIface GtkRecentChooserInterface;
-G_DEFINE_INTERFACE (GtkRecentChooser, gtk_recent_chooser, G_TYPE_OBJECT);
-
-
-static void
-gtk_recent_chooser_default_init (GtkRecentChooserInterface *iface)
-{
- GType iface_type = G_TYPE_FROM_INTERFACE (iface);
-
- /**
- * GtkRecentChooser::selection-changed:
- * @chooser: the object which received the signal
- *
- * This signal is emitted when there is a change in the set of
- * selected recently used resources. This can happen when a user
- * modifies the selection with the mouse or the keyboard, or when
- * explicitly calling functions to change the selection.
- *
- * Since: 2.10
- */
- chooser_signals[SELECTION_CHANGED] =
- g_signal_new (I_("selection-changed"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkRecentChooserIface, selection_changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /**
- * GtkRecentChooser::item-activated:
- * @chooser: the object which received the signal
- *
- * This signal is emitted when the user "activates" a recent item
- * in the recent chooser. This can happen by double-clicking on an item
- * in the recently used resources list, or by pressing
- * `Enter`.
- *
- * Since: 2.10
- */
- chooser_signals[ITEM_ACTIVATED] =
- g_signal_new (I_("item-activated"),
- iface_type,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkRecentChooserIface, item_activated),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- /**
- * GtkRecentChooser:recent-manager:
- *
- * The #GtkRecentManager instance used by the #GtkRecentChooser to
- * display the list of recently used resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("recent-manager",
- P_("Recent Manager"),
- P_("The RecentManager object to use"),
- GTK_TYPE_RECENT_MANAGER,
- GTK_PARAM_WRITABLE|G_PARAM_CONSTRUCT_ONLY));
-
- /**
- * GtkRecentManager:show-private:
- *
- * Whether this #GtkRecentChooser should display recently used resources
- * marked with the "private" flag. Such resources should be considered
- * private to the applications and groups that have added them.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("show-private",
- P_("Show Private"),
- P_("Whether the private items should be displayed"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:show-tips:
- *
- * Whether this #GtkRecentChooser should display a tooltip containing the
- * full path of the recently used resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("show-tips",
- P_("Show Tooltips"),
- P_("Whether there should be a tooltip on the item"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:show-icons:
- *
- * Whether this #GtkRecentChooser should display an icon near the item.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("show-icons",
- P_("Show Icons"),
- P_("Whether there should be an icon near the item"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:show-not-found:
- *
- * Whether this #GtkRecentChooser should display the recently used resources
- * even if not present anymore. Setting this to %FALSE will perform a
- * potentially expensive check on every local resource (every remote
- * resource will always be displayed).
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("show-not-found",
- P_("Show Not Found"),
- P_("Whether the items pointing to unavailable resources should be displayed"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:select-multiple:
- *
- * Allow the user to select multiple resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("select-multiple",
- P_("Select Multiple"),
- P_("Whether to allow multiple items to be selected"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:local-only:
- *
- * Whether this #GtkRecentChooser should display only local (file:)
- * resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_boolean ("local-only",
- P_("Local only"),
- P_("Whether the selected resource(s) should be limited to local file: URIs"),
- TRUE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:limit:
- *
- * The maximum number of recently used resources to be displayed,
- * or -1 to display all items.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_int ("limit",
- P_("Limit"),
- P_("The maximum number of items to be displayed"),
- -1, G_MAXINT, 50,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:sort-type:
- *
- * Sorting order to be used when displaying the recently used resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_enum ("sort-type",
- P_("Sort Type"),
- P_("The sorting order of the items displayed"),
- GTK_TYPE_RECENT_SORT_TYPE,
- GTK_RECENT_SORT_NONE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-
- /**
- * GtkRecentChooser:filter:
- *
- * The #GtkRecentFilter object to be used when displaying
- * the recently used resources.
- *
- * Since: 2.10
- */
- g_object_interface_install_property (iface,
- g_param_spec_object ("filter",
- P_("Filter"),
- P_("The current filter for selecting which resources are displayed"),
- GTK_TYPE_RECENT_FILTER,
- GTK_PARAM_READWRITE));
-}
-
-GQuark
-gtk_recent_chooser_error_quark (void)
-{
- return g_quark_from_static_string ("gtk-recent-chooser-error-quark");
-}
-
-/**
- * _gtk_recent_chooser_get_recent_manager:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the #GtkRecentManager used by @chooser.
- *
- * Returns: the recent manager for @chooser.
- *
- * Since: 2.10
- */
-GtkRecentManager *
-_gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_recent_manager (chooser);
-}
-
-/**
- * gtk_recent_chooser_set_show_private:
- * @chooser: a #GtkRecentChooser
- * @show_private: %TRUE to show private items, %FALSE otherwise
- *
- * Whether to show recently used resources marked registered as private.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
- gboolean show_private)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "show-private", show_private, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_show_private:
- * @chooser: a #GtkRecentChooser
- *
- * Returns whether @chooser should display recently used resources
- * registered as private.
- *
- * Returns: %TRUE if the recent chooser should show private items,
- * %FALSE otherwise.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser)
-{
- gboolean show_private;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "show-private", &show_private, NULL);
-
- return show_private;
-}
-
-/**
- * gtk_recent_chooser_set_show_not_found:
- * @chooser: a #GtkRecentChooser
- * @show_not_found: whether to show the local items we didn’t find
- *
- * Sets whether @chooser should display the recently used resources that
- * it didn’t find. This only applies to local resources.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
- gboolean show_not_found)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "show-not-found", show_not_found, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_show_not_found:
- * @chooser: a #GtkRecentChooser
- *
- * Retrieves whether @chooser should show the recently used resources that
- * were not found.
- *
- * Returns: %TRUE if the resources not found should be displayed, and
- * %FALSE otheriwse.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser)
-{
- gboolean show_not_found;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "show-not-found", &show_not_found, NULL);
-
- return show_not_found;
-}
-
-/**
- * gtk_recent_chooser_set_show_icons:
- * @chooser: a #GtkRecentChooser
- * @show_icons: whether to show an icon near the resource
- *
- * Sets whether @chooser should show an icon near the resource when
- * displaying it.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
- gboolean show_icons)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "show-icons", show_icons, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_show_icons:
- * @chooser: a #GtkRecentChooser
- *
- * Retrieves whether @chooser should show an icon near the resource.
- *
- * Returns: %TRUE if the icons should be displayed, %FALSE otherwise.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser)
-{
- gboolean show_icons;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "show-icons", &show_icons, NULL);
-
- return show_icons;
-}
-
-/**
- * gtk_recent_chooser_set_select_multiple:
- * @chooser: a #GtkRecentChooser
- * @select_multiple: %TRUE if @chooser can select more than one item
- *
- * Sets whether @chooser can select multiple items.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
- gboolean select_multiple)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "select-multiple", select_multiple, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_select_multiple:
- * @chooser: a #GtkRecentChooser
- *
- * Gets whether @chooser can select multiple items.
- *
- * Returns: %TRUE if @chooser can select more than one item.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser)
-{
- gboolean select_multiple;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "select-multiple", &select_multiple, NULL);
-
- return select_multiple;
-}
-
-/**
- * gtk_recent_chooser_set_local_only:
- * @chooser: a #GtkRecentChooser
- * @local_only: %TRUE if only local files can be shown
- *
- * Sets whether only local resources, that is resources using the file:// URI
- * scheme, should be shown in the recently used resources selector. If
- * @local_only is %TRUE (the default) then the shown resources are guaranteed
- * to be accessible through the operating system native file system.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
- gboolean local_only)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "local-only", local_only, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_local_only:
- * @chooser: a #GtkRecentChooser
- *
- * Gets whether only local resources should be shown in the recently used
- * resources selector. See gtk_recent_chooser_set_local_only()
- *
- * Returns: %TRUE if only local resources should be shown.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser)
-{
- gboolean local_only;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "local-only", &local_only, NULL);
-
- return local_only;
-}
-
-/**
- * gtk_recent_chooser_set_limit:
- * @chooser: a #GtkRecentChooser
- * @limit: a positive integer, or -1 for all items
- *
- * Sets the number of items that should be returned by
- * gtk_recent_chooser_get_items() and gtk_recent_chooser_get_uris().
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
- gint limit)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "limit", limit, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_limit:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the number of items returned by gtk_recent_chooser_get_items()
- * and gtk_recent_chooser_get_uris().
- *
- * Returns: A positive integer, or -1 meaning that all items are
- * returned.
- *
- * Since: 2.10
- */
-gint
-gtk_recent_chooser_get_limit (GtkRecentChooser *chooser)
-{
- gint limit;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), 10);
-
- g_object_get (chooser, "limit", &limit, NULL);
-
- return limit;
-}
-
-/**
- * gtk_recent_chooser_set_show_tips:
- * @chooser: a #GtkRecentChooser
- * @show_tips: %TRUE if tooltips should be shown
- *
- * Sets whether to show a tooltips containing the full path of each
- * recently used resource in a #GtkRecentChooser widget.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
- gboolean show_tips)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "show-tips", show_tips, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_show_tips:
- * @chooser: a #GtkRecentChooser
- *
- * Gets whether @chooser should display tooltips containing the full path
- * of a recently user resource.
- *
- * Returns: %TRUE if the recent chooser should show tooltips,
- * %FALSE otherwise.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser)
-{
- gboolean show_tips;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- g_object_get (chooser, "show-tips", &show_tips, NULL);
-
- return show_tips;
-}
-
-/**
- * gtk_recent_chooser_set_sort_type:
- * @chooser: a #GtkRecentChooser
- * @sort_type: sort order that the chooser should use
- *
- * Changes the sorting order of the recently used resources list displayed by
- * @chooser.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
- GtkRecentSortType sort_type)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_object_set (chooser, "sort-type", sort_type, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_sort_type:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the value set by gtk_recent_chooser_set_sort_type().
- *
- * Returns: the sorting order of the @chooser.
- *
- * Since: 2.10
- */
-GtkRecentSortType
-gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser)
-{
- GtkRecentSortType sort_type;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), GTK_RECENT_SORT_NONE);
-
- g_object_get (chooser, "sort-type", &sort_type, NULL);
-
- return sort_type;
-}
-
-/**
- * gtk_recent_chooser_set_sort_func:
- * @chooser: a #GtkRecentChooser
- * @sort_func: the comparison function
- * @sort_data: (allow-none): user data to pass to @sort_func, or %NULL
- * @data_destroy: (allow-none): destroy notifier for @sort_data, or %NULL
- *
- * Sets the comparison function used when sorting to be @sort_func. If
- * the @chooser has the sort type set to #GTK_RECENT_SORT_CUSTOM then
- * the chooser will sort using this function.
- *
- * To the comparison function will be passed two #GtkRecentInfo structs and
- * @sort_data; @sort_func should return a positive integer if the first
- * item comes before the second, zero if the two items are equal and
- * a negative integer if the first item comes after the second.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_sort_func (chooser,
- sort_func,
- sort_data,
- data_destroy);
-}
-
-/**
- * gtk_recent_chooser_set_current_uri:
- * @chooser: a #GtkRecentChooser
- * @uri: a URI
- * @error: (allow-none): return location for a #GError, or %NULL
- *
- * Sets @uri as the current URI for @chooser.
- *
- * Returns: %TRUE if the URI was found.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->set_current_uri (chooser, uri, error);
-}
-
-/**
- * gtk_recent_chooser_get_current_uri:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the URI currently selected by @chooser.
- *
- * Returns: a newly allocated string holding a URI.
- *
- * Since: 2.10
- */
-gchar *
-gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_current_uri (chooser);
-}
-
-/**
- * gtk_recent_chooser_get_current_item:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the #GtkRecentInfo currently selected by @chooser.
- *
- * Returns: a #GtkRecentInfo. Use gtk_recent_info_unref() when
- * when you have finished using it.
- *
- * Since: 2.10
- */
-GtkRecentInfo *
-gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser)
-{
- GtkRecentManager *manager;
- GtkRecentInfo *retval;
- gchar *uri;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- uri = gtk_recent_chooser_get_current_uri (chooser);
- if (!uri)
- return NULL;
-
- manager = _gtk_recent_chooser_get_recent_manager (chooser);
- retval = gtk_recent_manager_lookup_item (manager, uri, NULL);
- g_free (uri);
-
- return retval;
-}
-
-/**
- * gtk_recent_chooser_select_uri:
- * @chooser: a #GtkRecentChooser
- * @uri: a URI
- * @error: (allow-none): return location for a #GError, or %NULL
- *
- * Selects @uri inside @chooser.
- *
- * Returns: %TRUE if @uri was found.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), FALSE);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_uri (chooser, uri, error);
-}
-
-/**
- * gtk_recent_chooser_unselect_uri:
- * @chooser: a #GtkRecentChooser
- * @uri: a URI
- *
- * Unselects @uri inside @chooser.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_uri (chooser, uri);
-}
-
-/**
- * gtk_recent_chooser_select_all:
- * @chooser: a #GtkRecentChooser
- *
- * Selects all the items inside @chooser, if the @chooser supports
- * multiple selection.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_select_all (GtkRecentChooser *chooser)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->select_all (chooser);
-}
-
-/**
- * gtk_recent_chooser_unselect_all:
- * @chooser: a #GtkRecentChooser
- *
- * Unselects all the items inside @chooser.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->unselect_all (chooser);
-}
-
-/**
- * gtk_recent_chooser_get_items:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the list of recently used resources in form of #GtkRecentInfo objects.
- *
- * The return value of this function is affected by the “sort-type” and
- * “limit” properties of @chooser.
- *
- * Returns: (element-type GtkRecentInfo) (transfer full): A newly allocated
- * list of #GtkRecentInfo objects. You should
- * use gtk_recent_info_unref() on every item of the list, and then free
- * the list itself using g_list_free().
- *
- * Since: 2.10
- */
-GList *
-gtk_recent_chooser_get_items (GtkRecentChooser *chooser)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->get_items (chooser);
-}
-
-/**
- * gtk_recent_chooser_get_uris:
- * @chooser: a #GtkRecentChooser
- * @length: (out) (allow-none): return location for a the length of the
- * URI list, or %NULL
- *
- * Gets the URI of the recently used resources.
- *
- * The return value of this function is affected by the “sort-type” and “limit”
- * properties of @chooser.
- *
- * Since the returned array is %NULL terminated, @length may be %NULL.
- *
- * Returns: (array length=length zero-terminated=1) (transfer full):
- * A newly allocated, %NULL-terminated array of strings. Use
- * g_strfreev() to free it.
- *
- * Since: 2.10
- */
-gchar **
-gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
- gsize *length)
-{
- GList *items, *l;
- gchar **retval;
- gsize n_items, i;
-
- items = gtk_recent_chooser_get_items (chooser);
-
- n_items = g_list_length (items);
- retval = g_new0 (gchar *, n_items + 1);
-
- for (l = items, i = 0; l != NULL; l = l->next)
- {
- GtkRecentInfo *info = (GtkRecentInfo *) l->data;
- const gchar *uri;
-
- g_assert (info != NULL);
-
- uri = gtk_recent_info_get_uri (info);
- g_assert (uri != NULL);
-
- retval[i++] = g_strdup (uri);
- }
- retval[i] = NULL;
-
- if (length)
- *length = i;
-
- g_list_free_full (items, (GDestroyNotify) gtk_recent_info_unref);
-
- return retval;
-}
-
-/**
- * gtk_recent_chooser_add_filter:
- * @chooser: a #GtkRecentChooser
- * @filter: a #GtkRecentFilter
- *
- * Adds @filter to the list of #GtkRecentFilter objects held by @chooser.
- *
- * If no previous filter objects were defined, this function will call
- * gtk_recent_chooser_set_filter().
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->add_filter (chooser, filter);
-}
-
-/**
- * gtk_recent_chooser_remove_filter:
- * @chooser: a #GtkRecentChooser
- * @filter: a #GtkRecentFilter
- *
- * Removes @filter from the list of #GtkRecentFilter objects held by @chooser.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
-
- GTK_RECENT_CHOOSER_GET_IFACE (chooser)->remove_filter (chooser, filter);
-}
-
-/**
- * gtk_recent_chooser_list_filters:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the #GtkRecentFilter objects held by @chooser.
- *
- * Returns: (element-type GtkRecentFilter) (transfer container): A singly linked list
- * of #GtkRecentFilter objects. You
- * should just free the returned list using g_slist_free().
- *
- * Since: 2.10
- */
-GSList *
-gtk_recent_chooser_list_filters (GtkRecentChooser *chooser)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- return GTK_RECENT_CHOOSER_GET_IFACE (chooser)->list_filters (chooser);
-}
-
-/**
- * gtk_recent_chooser_set_filter:
- * @chooser: a #GtkRecentChooser
- * @filter: (allow-none): a #GtkRecentFilter
- *
- * Sets @filter as the current #GtkRecentFilter object used by @chooser
- * to affect the displayed recently used resources.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
- g_return_if_fail (filter == NULL || GTK_IS_RECENT_FILTER (filter));
-
- g_object_set (G_OBJECT (chooser), "filter", filter, NULL);
-}
-
-/**
- * gtk_recent_chooser_get_filter:
- * @chooser: a #GtkRecentChooser
- *
- * Gets the #GtkRecentFilter object currently used by @chooser to affect
- * the display of the recently used resources.
- *
- * Returns: (transfer none): a #GtkRecentFilter object.
- *
- * Since: 2.10
- */
-GtkRecentFilter *
-gtk_recent_chooser_get_filter (GtkRecentChooser *chooser)
-{
- GtkRecentFilter *filter;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- g_object_get (G_OBJECT (chooser), "filter", &filter, NULL);
-
- /* we need this hack because g_object_get() increases the refcount
- * of the returned object; see also gtk_file_chooser_get_filter()
- * inside gtkfilechooser.c
- */
- if (filter)
- g_object_unref (filter);
-
- return filter;
-}
-
-void
-_gtk_recent_chooser_item_activated (GtkRecentChooser *chooser)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_signal_emit (chooser, chooser_signals[ITEM_ACTIVATED], 0);
-}
-
-void
-_gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (chooser));
-
- g_signal_emit (chooser, chooser_signals[SELECTION_CHANGED], 0);
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooser.h - Abstract interface for recent file selectors GUIs
- *
- * Copyright (C) 2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_H__
-#define __GTK_RECENT_CHOOSER_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkwidget.h>
-#include <gtk/gtkrecentmanager.h>
-#include <gtk/gtkrecentfilter.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RECENT_CHOOSER (gtk_recent_chooser_get_type ())
-#define GTK_RECENT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER, GtkRecentChooser))
-#define GTK_IS_RECENT_CHOOSER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER))
-#define GTK_RECENT_CHOOSER_GET_IFACE(inst) (G_TYPE_INSTANCE_GET_INTERFACE ((inst), GTK_TYPE_RECENT_CHOOSER, GtkRecentChooserIface))
-
-/**
- * GtkRecentSortType:
- * @GTK_RECENT_SORT_NONE: Do not sort the returned list of recently used
- * resources.
- * @GTK_RECENT_SORT_MRU: Sort the returned list with the most recently used
- * items first.
- * @GTK_RECENT_SORT_LRU: Sort the returned list with the least recently used
- * items first.
- * @GTK_RECENT_SORT_CUSTOM: Sort the returned list using a custom sorting
- * function passed using gtk_recent_chooser_set_sort_func().
- *
- * Used to specify the sorting method to be applyed to the recently
- * used resource list.
- *
- * Since: 2.10
- */
-typedef enum
-{
- GTK_RECENT_SORT_NONE = 0,
- GTK_RECENT_SORT_MRU,
- GTK_RECENT_SORT_LRU,
- GTK_RECENT_SORT_CUSTOM
-} GtkRecentSortType;
-
-typedef gint (*GtkRecentSortFunc) (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer user_data);
-
-
-typedef struct _GtkRecentChooser GtkRecentChooser; /* dummy */
-typedef struct _GtkRecentChooserIface GtkRecentChooserIface;
-
-/**
- * GTK_RECENT_CHOOSER_ERROR:
- *
- * Used to get the #GError quark for #GtkRecentChooser errors.
- *
- * Since: 2.10
- */
-#define GTK_RECENT_CHOOSER_ERROR (gtk_recent_chooser_error_quark ())
-
-/**
- * GtkRecentChooserError:
- * @GTK_RECENT_CHOOSER_ERROR_NOT_FOUND: Indicates that a file does not exist
- * @GTK_RECENT_CHOOSER_ERROR_INVALID_URI: Indicates a malformed URI
- *
- * These identify the various errors that can occur while calling
- * #GtkRecentChooser functions.
- *
- * Since: 2.10
- */
-typedef enum
-{
- GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
- GTK_RECENT_CHOOSER_ERROR_INVALID_URI
-} GtkRecentChooserError;
-
-GDK_AVAILABLE_IN_ALL
-GQuark gtk_recent_chooser_error_quark (void);
-
-
-/**
- * GtkRecentChooserIface:
- * @set_current_uri: Sets uri as the current URI for chooser.
- * @get_current_uri: Gets the URI currently selected by chooser.
- * @select_uri: Selects uri inside chooser.
- * @unselect_uri: Unselects uri inside chooser.
- * @select_all: Selects all the items inside chooser, if the chooser
- * supports multiple selection.
- * @unselect_all: Unselects all the items inside chooser.
- * @get_items: Gets the list of recently used resources in form of
- * #GtkRecentInfo objects.
- * @get_recent_manager: Gets the #GtkRecentManager used by chooser.
- * @add_filter: Adds filter to the list of #GtkRecentFilter objects
- * held by chooser.
- * @remove_filter: Removes filter from the list of #GtkRecentFilter
- * objects held by chooser.
- * @list_filters: Gets the #GtkRecentFilter objects held by chooser.
- * @set_sort_func: Sets the comparison function used when sorting to
- * be sort_func.
- * @item_activated: Signal emitted when the user “activates” a recent
- * item in the recent chooser.
- * @selection_changed: Signal emitted when there is a change in the
- * set of selected recently used resources.
- */
-struct _GtkRecentChooserIface
-{
- /*< private >*/
- GTypeInterface base_iface;
-
- /*< public >*/
-
- /*
- * Methods
- */
- gboolean (* set_current_uri) (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
- gchar * (* get_current_uri) (GtkRecentChooser *chooser);
- gboolean (* select_uri) (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
- void (* unselect_uri) (GtkRecentChooser *chooser,
- const gchar *uri);
- void (* select_all) (GtkRecentChooser *chooser);
- void (* unselect_all) (GtkRecentChooser *chooser);
- GList * (* get_items) (GtkRecentChooser *chooser);
- GtkRecentManager *(* get_recent_manager) (GtkRecentChooser *chooser);
- void (* add_filter) (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
- void (* remove_filter) (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
- GSList * (* list_filters) (GtkRecentChooser *chooser);
- void (* set_sort_func) (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy);
-
- /*
- * Signals
- */
- void (* item_activated) (GtkRecentChooser *chooser);
- void (* selection_changed) (GtkRecentChooser *chooser);
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_chooser_get_type (void) G_GNUC_CONST;
-
-/*
- * Configuration
- */
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_show_private (GtkRecentChooser *chooser,
- gboolean show_private);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_show_private (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_show_not_found (GtkRecentChooser *chooser,
- gboolean show_not_found);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_show_not_found (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_select_multiple (GtkRecentChooser *chooser,
- gboolean select_multiple);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_select_multiple (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_limit (GtkRecentChooser *chooser,
- gint limit);
-GDK_AVAILABLE_IN_ALL
-gint gtk_recent_chooser_get_limit (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_local_only (GtkRecentChooser *chooser,
- gboolean local_only);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_local_only (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_show_tips (GtkRecentChooser *chooser,
- gboolean show_tips);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_show_tips (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_show_icons (GtkRecentChooser *chooser,
- gboolean show_icons);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_get_show_icons (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_sort_type (GtkRecentChooser *chooser,
- GtkRecentSortType sort_type);
-GDK_AVAILABLE_IN_ALL
-GtkRecentSortType gtk_recent_chooser_get_sort_type (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy);
-
-/*
- * Items handling
- */
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-gchar * gtk_recent_chooser_get_current_uri (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-GtkRecentInfo *gtk_recent_chooser_get_current_item (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_select_all (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_unselect_all (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-GList * gtk_recent_chooser_get_items (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-gchar ** gtk_recent_chooser_get_uris (GtkRecentChooser *chooser,
- gsize *length);
-
-/*
- * Filters
- */
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-GDK_AVAILABLE_IN_ALL
-GSList * gtk_recent_chooser_list_filters (GtkRecentChooser *chooser);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_set_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-GDK_AVAILABLE_IN_ALL
-GtkRecentFilter *gtk_recent_chooser_get_filter (GtkRecentChooser *chooser);
-
-
-G_END_DECLS
-
-#endif /* __GTK_RECENT_CHOOSER_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserdefault.c
- * Copyright (C) 2005-2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <time.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#include "gtkicontheme.h"
-#include "gtksettings.h"
-#include "gtktreeview.h"
-#include "gtkliststore.h"
-#include "gtkbutton.h"
-#include "gtkcelllayout.h"
-#include "gtkcheckmenuitem.h"
-#include "gtkcomboboxtext.h"
-#include "gtkcssiconthemevalueprivate.h"
-#include "gtkdragsource.h"
-#include "gtkentry.h"
-#include "gtkexpander.h"
-#include "gtkframe.h"
-#include "gtkbox.h"
-#include "gtkpaned.h"
-#include "gtkimage.h"
-#include "gtkintl.h"
-#include "gtklabel.h"
-#include "gtkmenuitem.h"
-#include "gtkmessagedialog.h"
-#include "gtkscrolledwindow.h"
-#include "gtkseparatormenuitem.h"
-#include "gtksizegroup.h"
-#include "gtksizerequest.h"
-#include "gtkstylecontextprivate.h"
-#include "gtktreemodelsort.h"
-#include "gtktreemodelfilter.h"
-#include "gtktreeselection.h"
-#include "gtktreestore.h"
-#include "gtktooltip.h"
-#include "gtktypebuiltins.h"
-#include "gtkorientable.h"
-#include "gtkwindowgroup.h"
-#include "gtkgesturemultipress.h"
-
-#include "gtkrecentmanager.h"
-#include "gtkrecentfilter.h"
-#include "gtkrecentchooser.h"
-#include "gtkrecentchooserprivate.h"
-#include "gtkrecentchooserutils.h"
-#include "gtkrecentchooserdefault.h"
-
-typedef struct
-{
- GtkRecentManager *manager;
- gulong manager_changed_id;
- guint local_manager : 1;
-
- /* RecentChooser properties */
- gint limit;
- GtkRecentSortType sort_type;
- guint show_private : 1;
- guint show_not_found : 1;
- guint select_multiple : 1;
- guint show_tips : 1;
- guint show_icons : 1;
- guint local_only : 1;
-
- guint limit_set : 1;
-
- GSList *filters;
- GtkRecentFilter *current_filter;
- GtkWidget *filter_combo_hbox;
- GtkWidget *filter_combo;
-
- GtkRecentSortFunc sort_func;
- gpointer sort_data;
- GDestroyNotify sort_data_destroy;
-
- GtkWidget *recent_view;
- GtkListStore *recent_store;
- GtkTreeViewColumn *icon_column;
- GtkTreeViewColumn *meta_column;
- GtkCellRenderer *icon_renderer;
- GtkCellRenderer *meta_renderer;
- GtkTreeSelection *selection;
-
- GtkWidget *recent_popup_menu;
- GtkWidget *recent_popup_menu_copy_item;
- GtkWidget *recent_popup_menu_remove_item;
- GtkWidget *recent_popup_menu_clear_item;
- GtkWidget *recent_popup_menu_show_private_item;
-
- GtkGesture *multipress_gesture;
-
- guint load_id;
- GList *recent_items;
- gint n_recent_items;
- gint loaded_items;
- guint load_state;
-} GtkRecentChooserDefaultPrivate;
-
-struct _GtkRecentChooserDefault
-{
- GtkBox parent_instance;
-
- GtkRecentChooserDefaultPrivate *priv;
-};
-
-typedef struct _GtkRecentChooserDefaultClass
-{
- GtkBoxClass parent_class;
-} GtkRecentChooserDefaultClass;
-
-/* Keep inline with GtkTreeStore defined in gtkrecentchooserdefault.ui */
-enum {
- RECENT_URI_COLUMN,
- RECENT_DISPLAY_NAME_COLUMN,
- RECENT_INFO_COLUMN,
- N_RECENT_COLUMNS
-};
-
-enum {
- LOAD_EMPTY, /* initial state: the model is empty */
- LOAD_PRELOAD, /* the model is loading and not inserted in the tree yet */
- LOAD_LOADING, /* the model is fully loaded but not inserted */
- LOAD_FINISHED /* the model is fully loaded and inserted */
-};
-
-#define FALLBACK_ITEM_LIMIT 20
-
-#define NUM_CHARS 40
-#define NUM_LINES 9
-
-#define DEFAULT_RECENT_FILES_LIMIT 50
-
-\f
-
-/* GObject */
-static void gtk_recent_chooser_default_finalize (GObject *object);
-static void gtk_recent_chooser_default_dispose (GObject *object);
-static void gtk_recent_chooser_default_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_recent_chooser_default_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-/* GtkRecentChooserIface */
-static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
-static gboolean gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static gchar * gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser);
-static gboolean gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static void gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri);
-static void gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser);
-static void gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser);
-static GList * gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser);
-static GtkRecentManager *gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser);
-static void gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy);
-static void gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static void gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static GSList * gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser);
-
-
-static void gtk_recent_chooser_default_map (GtkWidget *widget);
-
-static void set_current_filter (GtkRecentChooserDefault *impl,
- GtkRecentFilter *filter);
-
-static void reload_recent_items (GtkRecentChooserDefault *impl);
-static void chooser_set_model (GtkRecentChooserDefault *impl);
-
-static void set_recent_manager (GtkRecentChooserDefault *impl,
- GtkRecentManager *manager);
-
-static void chooser_set_sort_type (GtkRecentChooserDefault *impl,
- GtkRecentSortType sort_type);
-
-static void recent_manager_changed_cb (GtkRecentManager *manager,
- gpointer user_data);
-static void recent_icon_data_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data);
-static void recent_meta_data_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data);
-
-static void selection_changed_cb (GtkTreeSelection *z,
- gpointer user_data);
-static void row_activated_cb (GtkTreeView *tree_view,
- GtkTreePath *tree_path,
- GtkTreeViewColumn *tree_column,
- gpointer user_data);
-static void filter_combo_changed_cb (GtkComboBox *combo_box,
- gpointer user_data);
-
-static void remove_all_activated_cb (GtkMenuItem *menu_item,
- gpointer user_data);
-static void remove_item_activated_cb (GtkMenuItem *menu_item,
- gpointer user_data);
-static void show_private_toggled_cb (GtkCheckMenuItem *menu_item,
- gpointer user_data);
-
-static void multi_press_cb (GtkGesture *gesture,
- int n_press,
- double x,
- double y,
- gpointer user_data);
-
-static gboolean recent_view_popup_menu_cb (GtkWidget *widget,
- gpointer user_data);
-
-static void recent_view_drag_begin_cb (GtkWidget *widget,
- GdkDragContext *context,
- gpointer user_data);
-static void recent_view_drag_data_get_cb (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time_,
- gpointer data);
-static gboolean recent_view_query_tooltip_cb (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_tip,
- GtkTooltip *tooltip,
- gpointer user_data);
-
-G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDefault,
- _gtk_recent_chooser_default,
- GTK_TYPE_BOX,
- G_ADD_PRIVATE (GtkRecentChooserDefault)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
- gtk_recent_chooser_iface_init))
-
-static void
-gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
-{
- iface->set_current_uri = gtk_recent_chooser_default_set_current_uri;
- iface->get_current_uri = gtk_recent_chooser_default_get_current_uri;
- iface->select_uri = gtk_recent_chooser_default_select_uri;
- iface->unselect_uri = gtk_recent_chooser_default_unselect_uri;
- iface->select_all = gtk_recent_chooser_default_select_all;
- iface->unselect_all = gtk_recent_chooser_default_unselect_all;
- iface->get_items = gtk_recent_chooser_default_get_items;
- iface->get_recent_manager = gtk_recent_chooser_default_get_recent_manager;
- iface->set_sort_func = gtk_recent_chooser_default_set_sort_func;
- iface->add_filter = gtk_recent_chooser_default_add_filter;
- iface->remove_filter = gtk_recent_chooser_default_remove_filter;
- iface->list_filters = gtk_recent_chooser_default_list_filters;
-}
-
-static void
-_gtk_recent_chooser_default_class_init (GtkRecentChooserDefaultClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- gobject_class->set_property = gtk_recent_chooser_default_set_property;
- gobject_class->get_property = gtk_recent_chooser_default_get_property;
- gobject_class->dispose = gtk_recent_chooser_default_dispose;
- gobject_class->finalize = gtk_recent_chooser_default_finalize;
-
- widget_class->map = gtk_recent_chooser_default_map;
-
- _gtk_recent_chooser_install_properties (gobject_class);
-
- /* Bind class to template
- */
- gtk_widget_class_set_template_from_resource (widget_class,
- "/org/gtk/libgtk/ui/gtkrecentchooserdefault.ui");
-
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo_hbox);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, filter_combo);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_view);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, recent_store);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_column);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_column);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, icon_renderer);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, meta_renderer);
- gtk_widget_class_bind_template_child_private (widget_class, GtkRecentChooserDefault, selection);
-
- gtk_widget_class_bind_template_callback (widget_class, selection_changed_cb);
- gtk_widget_class_bind_template_callback (widget_class, row_activated_cb);
- gtk_widget_class_bind_template_callback (widget_class, filter_combo_changed_cb);
- gtk_widget_class_bind_template_callback (widget_class, recent_view_popup_menu_cb);
- gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_begin_cb);
- gtk_widget_class_bind_template_callback (widget_class, recent_view_drag_data_get_cb);
- gtk_widget_class_bind_template_callback (widget_class, recent_view_query_tooltip_cb);
-}
-
-static void
-_gtk_recent_chooser_default_init (GtkRecentChooserDefault *impl)
-{
- GtkRecentChooserDefaultPrivate *priv;
-
- impl->priv = priv = _gtk_recent_chooser_default_get_instance_private (impl);
-
- /* by default, we use the global manager */
- priv->local_manager = FALSE;
-
- priv->limit = FALLBACK_ITEM_LIMIT;
- priv->sort_type = GTK_RECENT_SORT_NONE;
-
- priv->show_icons = TRUE;
- priv->show_private = FALSE;
- priv->show_not_found = TRUE;
- priv->show_tips = FALSE;
- priv->select_multiple = FALSE;
- priv->local_only = TRUE;
-
- priv->current_filter = NULL;
-
- priv->recent_items = NULL;
- priv->n_recent_items = 0;
- priv->loaded_items = 0;
-
- priv->load_state = LOAD_EMPTY;
-
- gtk_widget_init_template (GTK_WIDGET (impl));
-
- g_object_set_data (G_OBJECT (priv->recent_view),
- "GtkRecentChooserDefault", impl);
-
- gtk_tree_view_column_set_cell_data_func (priv->icon_column,
- priv->icon_renderer,
- recent_icon_data_func,
- impl,
- NULL);
- gtk_tree_view_column_set_cell_data_func (priv->meta_column,
- priv->meta_renderer,
- recent_meta_data_func,
- impl,
- NULL);
- gtk_drag_source_set (priv->recent_view,
- GDK_BUTTON1_MASK,
- NULL,
- GDK_ACTION_COPY);
- gtk_drag_source_add_uri_targets (priv->recent_view);
-
- priv->multipress_gesture = gtk_gesture_multi_press_new (priv->recent_view);
- gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->multipress_gesture), GDK_BUTTON_SECONDARY);
- g_signal_connect (priv->multipress_gesture, "pressed",
- G_CALLBACK (multi_press_cb), impl);
-}
-
-static void
-gtk_recent_chooser_default_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
-
- switch (prop_id)
- {
- case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
- set_recent_manager (impl, g_value_get_object (value));
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- if (impl->priv->show_private != g_value_get_boolean (value))
- {
- impl->priv->show_private = g_value_get_boolean (value);
- if (impl->priv->recent_popup_menu_show_private_item)
- {
- GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM (impl->priv->recent_popup_menu_show_private_item);
- g_signal_handlers_block_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
- gtk_check_menu_item_set_active (item, impl->priv->show_private);
- g_signal_handlers_unblock_by_func (item, G_CALLBACK (show_private_toggled_cb), impl);
- }
- reload_recent_items (impl);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- if (impl->priv->show_not_found != g_value_get_boolean (value))
- {
- impl->priv->show_not_found = g_value_get_boolean (value);
- reload_recent_items (impl);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- if (impl->priv->show_tips != g_value_get_boolean (value))
- {
- impl->priv->show_tips = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- if (impl->priv->show_icons != g_value_get_boolean (value))
- {
- impl->priv->show_icons = g_value_get_boolean (value);
- gtk_tree_view_column_set_visible (impl->priv->icon_column, impl->priv->show_icons);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
- if (impl->priv->select_multiple != g_value_get_boolean (value))
- {
- impl->priv->select_multiple = g_value_get_boolean (value);
- if (impl->priv->select_multiple)
- gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_MULTIPLE);
- else
- gtk_tree_selection_set_mode (impl->priv->selection, GTK_SELECTION_SINGLE);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- if (impl->priv->local_only != g_value_get_boolean (value))
- {
- impl->priv->local_only = g_value_get_boolean (value);
- reload_recent_items (impl);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_LIMIT:
- if (impl->priv->limit != g_value_get_int (value))
- {
- impl->priv->limit = g_value_get_int (value);
- impl->priv->limit_set = TRUE;
- reload_recent_items (impl);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- chooser_set_sort_type (impl, g_value_get_enum (value));
- break;
- case GTK_RECENT_CHOOSER_PROP_FILTER:
- set_current_filter (impl, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_recent_chooser_default_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
-
- switch (prop_id)
- {
- case GTK_RECENT_CHOOSER_PROP_LIMIT:
- g_value_set_int (value, impl->priv->limit);
- break;
- case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- g_value_set_enum (value, impl->priv->sort_type);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- g_value_set_boolean (value, impl->priv->show_private);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- g_value_set_boolean (value, impl->priv->show_icons);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- g_value_set_boolean (value, impl->priv->show_not_found);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- g_value_set_boolean (value, impl->priv->show_tips);
- break;
- case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- g_value_set_boolean (value, impl->priv->local_only);
- break;
- case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
- g_value_set_boolean (value, impl->priv->select_multiple);
- break;
- case GTK_RECENT_CHOOSER_PROP_FILTER:
- g_value_set_object (value, impl->priv->current_filter);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_recent_chooser_default_dispose (GObject *object)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
-
- if (impl->priv->load_id)
- {
- g_source_remove (impl->priv->load_id);
- impl->priv->load_state = LOAD_EMPTY;
- impl->priv->load_id = 0;
- }
-
- g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
- impl->priv->recent_items = NULL;
-
- if (impl->priv->manager && impl->priv->manager_changed_id)
- {
- g_signal_handler_disconnect (impl->priv->manager, impl->priv->manager_changed_id);
- impl->priv->manager_changed_id = 0;
- }
-
- if (impl->priv->filters)
- {
- g_slist_free_full (impl->priv->filters, g_object_unref);
- impl->priv->filters = NULL;
- }
-
- if (impl->priv->current_filter)
- {
- g_object_unref (impl->priv->current_filter);
- impl->priv->current_filter = NULL;
- }
-
- G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->dispose (object);
-}
-
-static void
-gtk_recent_chooser_default_finalize (GObject *object)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (object);
-
- impl->priv->manager = NULL;
-
- if (impl->priv->sort_data_destroy)
- {
- impl->priv->sort_data_destroy (impl->priv->sort_data);
- impl->priv->sort_data_destroy = NULL;
- }
-
- g_object_unref (impl->priv->multipress_gesture);
-
- impl->priv->sort_data = NULL;
- impl->priv->sort_func = NULL;
-
- G_OBJECT_CLASS (_gtk_recent_chooser_default_parent_class)->finalize (object);
-}
-
-/* Shows an error dialog set as transient for the specified window */
-static void
-error_message_with_parent (GtkWindow *parent,
- const gchar *msg,
- const gchar *detail)
-{
- GtkWidget *dialog;
-
- dialog = gtk_message_dialog_new (parent,
- GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
- GTK_MESSAGE_ERROR,
- GTK_BUTTONS_OK,
- "%s",
- msg);
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- "%s", detail);
-
- if (gtk_window_has_group (parent))
- gtk_window_group_add_window (gtk_window_get_group (parent),
- GTK_WINDOW (dialog));
-
- gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
-}
-
-/* Returns a toplevel GtkWindow, or NULL if none */
-static GtkWindow *
-get_toplevel (GtkWidget *widget)
-{
- GtkWidget *toplevel;
-
- toplevel = gtk_widget_get_toplevel (widget);
- if (!gtk_widget_is_toplevel (toplevel))
- return NULL;
- else
- return GTK_WINDOW (toplevel);
-}
-
-/* Shows an error dialog for the file chooser */
-static void
-error_message (GtkRecentChooserDefault *impl,
- const gchar *msg,
- const gchar *detail)
-{
- error_message_with_parent (get_toplevel (GTK_WIDGET (impl)), msg, detail);
-}
-
-static void
-set_busy_cursor (GtkRecentChooserDefault *impl,
- gboolean busy)
-{
- GtkWindow *toplevel;
-
- toplevel = get_toplevel (GTK_WIDGET (impl));
- if (!toplevel || !gtk_widget_get_realized (GTK_WIDGET (toplevel)))
- return;
-
- if (busy)
- gtk_widget_set_cursor_from_name (GTK_WIDGET (toplevel), "progress");
- else
- gtk_widget_set_cursor (GTK_WIDGET (toplevel), NULL);
-}
-
-static void
-chooser_set_model (GtkRecentChooserDefault *impl)
-{
- g_assert (impl->priv->recent_store != NULL);
- g_assert (impl->priv->load_state == LOAD_LOADING);
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view),
- GTK_TREE_MODEL (impl->priv->recent_store));
- gtk_tree_view_columns_autosize (GTK_TREE_VIEW (impl->priv->recent_view));
- gtk_tree_view_set_enable_search (GTK_TREE_VIEW (impl->priv->recent_view), TRUE);
- gtk_tree_view_set_search_column (GTK_TREE_VIEW (impl->priv->recent_view),
- RECENT_DISPLAY_NAME_COLUMN);
-
- impl->priv->load_state = LOAD_FINISHED;
-}
-
-static gboolean
-load_recent_items (gpointer user_data)
-{
- GtkRecentChooserDefault *impl;
- GtkRecentInfo *info;
- GtkTreeIter iter;
- const gchar *uri, *name;
- gboolean retval;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
- (impl->priv->load_state == LOAD_PRELOAD));
-
- /* store the items for multiple runs */
- if (!impl->priv->recent_items)
- {
- impl->priv->recent_items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (impl));
- if (!impl->priv->recent_items)
- {
- impl->priv->load_state = LOAD_FINISHED;
- impl->priv->load_id = 0;
- return FALSE;
- }
-
- impl->priv->n_recent_items = g_list_length (impl->priv->recent_items);
- impl->priv->loaded_items = 0;
- impl->priv->load_state = LOAD_PRELOAD;
- }
-
- info = (GtkRecentInfo *) g_list_nth_data (impl->priv->recent_items,
- impl->priv->loaded_items);
- g_assert (info);
-
- uri = gtk_recent_info_get_uri (info);
- name = gtk_recent_info_get_display_name (info);
-
- /* at this point, everything goes inside the model; operations on the
- * visualization of items inside the model are done in the cell data
- * funcs (remember that there are two of those: one for the icon and
- * one for the text), while the filtering is done only when a filter
- * is actually loaded. */
- gtk_list_store_append (impl->priv->recent_store, &iter);
- gtk_list_store_set (impl->priv->recent_store, &iter,
- RECENT_URI_COLUMN, uri, /* uri */
- RECENT_DISPLAY_NAME_COLUMN, name, /* display_name */
- RECENT_INFO_COLUMN, info, /* info */
- -1);
-
- impl->priv->loaded_items += 1;
-
- if (impl->priv->loaded_items == impl->priv->n_recent_items)
- {
- /* we have finished loading, so we remove the items cache */
- impl->priv->load_state = LOAD_LOADING;
-
- g_list_free_full (impl->priv->recent_items, (GDestroyNotify) gtk_recent_info_unref);
-
- impl->priv->recent_items = NULL;
- impl->priv->n_recent_items = 0;
- impl->priv->loaded_items = 0;
-
- /* load the filled up model */
- chooser_set_model (impl);
-
- retval = FALSE;
- impl->priv->load_id = 0;
- }
- else
- {
- /* we did not finish, so continue loading */
- retval = TRUE;
- }
-
- return retval;
-}
-
-static void
-cleanup_after_load (gpointer user_data)
-{
- GtkRecentChooserDefault *impl;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- if (impl->priv->load_id != 0)
- {
- g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
- (impl->priv->load_state == LOAD_PRELOAD) ||
- (impl->priv->load_state == LOAD_LOADING) ||
- (impl->priv->load_state == LOAD_FINISHED));
-
- /* we have officialy finished loading all the items,
- * so we can reset the state machine
- */
- impl->priv->load_id = 0;
- impl->priv->load_state = LOAD_EMPTY;
- }
- else
- g_assert ((impl->priv->load_state == LOAD_EMPTY) ||
- (impl->priv->load_state == LOAD_LOADING) ||
- (impl->priv->load_state == LOAD_FINISHED));
-
- set_busy_cursor (impl, FALSE);
-}
-
-/* clears the current model and reloads the recently used resources */
-static void
-reload_recent_items (GtkRecentChooserDefault *impl)
-{
- /* reload is already in progress - do not disturb */
- if (impl->priv->load_id)
- return;
-
- gtk_tree_view_set_model (GTK_TREE_VIEW (impl->priv->recent_view), NULL);
- gtk_list_store_clear (impl->priv->recent_store);
-
- if (!impl->priv->limit_set)
- impl->priv->limit = DEFAULT_RECENT_FILES_LIMIT;
-
- set_busy_cursor (impl, TRUE);
-
- impl->priv->load_state = LOAD_EMPTY;
- impl->priv->load_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
- load_recent_items,
- impl,
- cleanup_after_load);
- g_source_set_name_by_id (impl->priv->load_id, "[gtk+] load_recent_items");
-}
-
-/* taken form gtkfilechooserdialog.c */
-static void
-set_default_size (GtkRecentChooserDefault *impl)
-{
- GtkScrolledWindow *scrollw;
- GtkWidget *widget;
- gint width, height;
- double font_size;
- GdkDisplay *display;
- GdkMonitor *monitor;
- GtkRequisition req;
- GdkRectangle workarea;
- GtkStyleContext *context;
-
- widget = GTK_WIDGET (impl);
- context = gtk_widget_get_style_context (widget);
-
- /* Size based on characters and the icon size */
- gtk_style_context_get (context, "font-size", &font_size, NULL);
-
- width = 16 + font_size * NUM_CHARS + 0.5;
- height = (16 + font_size) * NUM_LINES + 0.5;
-
- /* Use at least the requisition size... */
- gtk_widget_get_preferred_size (widget, &req, NULL);
- width = MAX (width, req.width);
- height = MAX (height, req.height);
-
- /* ... but no larger than the monitor */
- display = gtk_widget_get_display (widget);
- monitor = gdk_display_get_monitor_at_window (display, gtk_widget_get_window (widget));
- gdk_monitor_get_workarea (monitor, &workarea);
-
- width = MIN (width, workarea.width * 3 / 4);
- height = MIN (height, workarea.height * 3 / 4);
-
- /* Set size */
- scrollw = GTK_SCROLLED_WINDOW (gtk_widget_get_parent (impl->priv->recent_view));
- gtk_scrolled_window_set_min_content_width (scrollw, width);
- gtk_scrolled_window_set_min_content_height (scrollw, height);
-}
-
-static void
-gtk_recent_chooser_default_map (GtkWidget *widget)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (widget);
-
- GTK_WIDGET_CLASS (_gtk_recent_chooser_default_parent_class)->map (widget);
-
- /* reloads everything */
- reload_recent_items (impl);
-
- set_default_size (impl);
-}
-
-static void
-recent_icon_data_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkRecentInfo *info = NULL;
- GIcon *icon;
-
- gtk_tree_model_get (model, iter, RECENT_INFO_COLUMN, &info, -1);
- g_assert (info != NULL);
-
- icon = gtk_recent_info_get_gicon (info);
- g_object_set (cell, "gicon", icon, NULL);
-
- if (icon != NULL)
- g_object_unref (icon);
-
- gtk_recent_info_unref (info);
-}
-
-static void
-recent_meta_data_func (GtkTreeViewColumn *tree_column,
- GtkCellRenderer *cell,
- GtkTreeModel *model,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- GtkRecentInfo *info = NULL;
- gchar *name;
-
- gtk_tree_model_get (model, iter,
- RECENT_DISPLAY_NAME_COLUMN, &name,
- RECENT_INFO_COLUMN, &info,
- -1);
- g_assert (info != NULL);
-
- if (!name)
- name = gtk_recent_info_get_short_name (info);
-
- g_object_set (cell, "text", name, NULL);
-
- g_free (name);
- gtk_recent_info_unref (info);
-}
-
-
-static gchar *
-gtk_recent_chooser_default_get_current_uri (GtkRecentChooser *chooser)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- g_assert (impl->priv->selection != NULL);
-
- if (!impl->priv->select_multiple)
- {
- GtkTreeModel *model;
- GtkTreeIter iter;
- gchar *uri = NULL;
-
- if (!gtk_tree_selection_get_selected (impl->priv->selection, &model, &iter))
- return NULL;
-
- gtk_tree_model_get (model, &iter, RECENT_URI_COLUMN, &uri, -1);
-
- return uri;
- }
-
- return NULL;
-}
-
-typedef struct
-{
- guint found : 1;
- guint do_select : 1;
- guint do_activate : 1;
-
- gchar *uri;
-
- GtkRecentChooserDefault *impl;
-} SelectURIData;
-
-static gboolean
-scan_for_uri_cb (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- SelectURIData *select_data = (SelectURIData *) user_data;
- gchar *uri = NULL;
-
- if (!select_data)
- return TRUE;
-
- if (select_data->found)
- return TRUE;
-
- gtk_tree_model_get (model, iter, RECENT_URI_COLUMN, &uri, -1);
- if (!uri)
- return FALSE;
-
- if (strcmp (uri, select_data->uri) == 0)
- {
- select_data->found = TRUE;
-
- if (select_data->do_activate)
- gtk_tree_view_row_activated (GTK_TREE_VIEW (select_data->impl->priv->recent_view),
- path,
- select_data->impl->priv->meta_column);
-
- if (select_data->do_select)
- gtk_tree_selection_select_path (select_data->impl->priv->selection, path);
- else
- gtk_tree_selection_unselect_path (select_data->impl->priv->selection, path);
-
- g_free (uri);
-
- return TRUE;
- }
-
- g_free (uri);
-
- return FALSE;
-}
-
-static gboolean
-gtk_recent_chooser_default_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
- SelectURIData *data;
-
- data = g_new0 (SelectURIData, 1);
- data->uri = g_strdup (uri);
- data->impl = impl;
- data->found = FALSE;
- data->do_activate = TRUE;
- data->do_select = TRUE;
-
- gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
- scan_for_uri_cb,
- data);
-
- if (!data->found)
- {
- g_free (data->uri);
- g_free (data);
-
- g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
- GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
- _("No item for URI “%s” found"),
- uri);
- return FALSE;
- }
-
- g_free (data->uri);
- g_free (data);
-
- return TRUE;
-}
-
-static gboolean
-gtk_recent_chooser_default_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
- SelectURIData *data;
-
- data = g_new0 (SelectURIData, 1);
- data->uri = g_strdup (uri);
- data->impl = impl;
- data->found = FALSE;
- data->do_activate = FALSE;
- data->do_select = TRUE;
-
- gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
- scan_for_uri_cb,
- data);
-
- if (!data->found)
- {
- g_free (data->uri);
- g_free (data);
-
- g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
- GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
- _("No item for URI “%s” found"),
- uri);
- return FALSE;
- }
-
- g_free (data->uri);
- g_free (data);
-
- return TRUE;
-}
-
-static void
-gtk_recent_chooser_default_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
- SelectURIData *data;
-
- data = g_new0 (SelectURIData, 1);
- data->uri = g_strdup (uri);
- data->impl = impl;
- data->found = FALSE;
- data->do_activate = FALSE;
- data->do_select = FALSE;
-
- gtk_tree_model_foreach (GTK_TREE_MODEL (impl->priv->recent_store),
- scan_for_uri_cb,
- data);
-
- g_free (data->uri);
- g_free (data);
-}
-
-static void
-gtk_recent_chooser_default_select_all (GtkRecentChooser *chooser)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- if (!impl->priv->select_multiple)
- return;
-
- gtk_tree_selection_select_all (impl->priv->selection);
-}
-
-static void
-gtk_recent_chooser_default_unselect_all (GtkRecentChooser *chooser)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- gtk_tree_selection_unselect_all (impl->priv->selection);
-}
-
-static void
-gtk_recent_chooser_default_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- if (impl->priv->sort_data_destroy)
- {
- impl->priv->sort_data_destroy (impl->priv->sort_data);
- impl->priv->sort_data_destroy = NULL;
- }
-
- impl->priv->sort_func = NULL;
- impl->priv->sort_data = NULL;
-
- if (sort_func)
- {
- impl->priv->sort_func = sort_func;
- impl->priv->sort_data = sort_data;
- impl->priv->sort_data_destroy = data_destroy;
- }
-}
-
-static GList *
-gtk_recent_chooser_default_get_items (GtkRecentChooser *chooser)
-{
- GtkRecentChooserDefault *impl;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- return _gtk_recent_chooser_get_items (chooser,
- impl->priv->current_filter,
- impl->priv->sort_func,
- impl->priv->sort_data);
-}
-
-static GtkRecentManager *
-gtk_recent_chooser_default_get_recent_manager (GtkRecentChooser *chooser)
-{
- return GTK_RECENT_CHOOSER_DEFAULT (chooser)->priv->manager;
-}
-
-static void
-show_filters (GtkRecentChooserDefault *impl,
- gboolean show)
-{
- if (show)
- gtk_widget_show (impl->priv->filter_combo_hbox);
- else
- gtk_widget_hide (impl->priv->filter_combo_hbox);
-}
-
-static void
-gtk_recent_chooser_default_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- GtkRecentChooserDefault *impl;
- const gchar *name;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- if (g_slist_find (impl->priv->filters, filter))
- {
- g_warning ("gtk_recent_chooser_add_filter() called on filter already in list");
- return;
- }
-
- g_object_ref_sink (filter);
- impl->priv->filters = g_slist_append (impl->priv->filters, filter);
-
- /* display new filter */
- name = gtk_recent_filter_get_name (filter);
- if (!name)
- name = _("Untitled filter");
-
- gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (impl->priv->filter_combo), name);
-
- if (!g_slist_find (impl->priv->filters, impl->priv->current_filter))
- set_current_filter (impl, filter);
-
- show_filters (impl, TRUE);
-}
-
-static void
-gtk_recent_chooser_default_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
- GtkTreeModel *model;
- GtkTreeIter iter;
- gint filter_idx;
-
- filter_idx = g_slist_index (impl->priv->filters, filter);
-
- if (filter_idx < 0)
- {
- g_warning ("gtk_recent_chooser_remove_filter() called on filter not in list");
- return;
- }
-
- impl->priv->filters = g_slist_remove (impl->priv->filters, filter);
-
- if (filter == impl->priv->current_filter)
- {
- if (impl->priv->filters)
- set_current_filter (impl, impl->priv->filters->data);
- else
- set_current_filter (impl, NULL);
- }
-
- model = gtk_combo_box_get_model (GTK_COMBO_BOX (impl->priv->filter_combo));
- gtk_tree_model_iter_nth_child (model, &iter, NULL, filter_idx);
- gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
-
- g_object_unref (filter);
-
- if (!impl->priv->filters)
- show_filters (impl, FALSE);
-}
-
-static GSList *
-gtk_recent_chooser_default_list_filters (GtkRecentChooser *chooser)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (chooser);
-
- return g_slist_copy (impl->priv->filters);
-}
-
-static void
-set_current_filter (GtkRecentChooserDefault *impl,
- GtkRecentFilter *filter)
-{
- if (impl->priv->current_filter != filter)
- {
- gint filter_idx;
-
- filter_idx = g_slist_index (impl->priv->filters, filter);
- if (impl->priv->filters && filter && filter_idx < 0)
- return;
-
- if (impl->priv->current_filter)
- g_object_unref (impl->priv->current_filter);
-
- impl->priv->current_filter = filter;
-
- if (impl->priv->current_filter)
- {
- g_object_ref_sink (impl->priv->current_filter);
- }
-
- if (impl->priv->filters)
- gtk_combo_box_set_active (GTK_COMBO_BOX (impl->priv->filter_combo),
- filter_idx);
-
- if (impl->priv->recent_store)
- reload_recent_items (impl);
-
- g_object_notify (G_OBJECT (impl), "filter");
- }
-}
-
-static void
-chooser_set_sort_type (GtkRecentChooserDefault *impl,
- GtkRecentSortType sort_type)
-{
- if (impl->priv->sort_type != sort_type)
- {
- impl->priv->sort_type = sort_type;
- reload_recent_items (impl);
- g_object_notify (G_OBJECT (impl), "sort-type");
- }
-}
-
-static void
-recent_manager_changed_cb (GtkRecentManager *manager,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- reload_recent_items (impl);
-}
-
-static void
-selection_changed_cb (GtkTreeSelection *selection,
- gpointer user_data)
-{
- _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
-}
-
-static void
-row_activated_cb (GtkTreeView *tree_view,
- GtkTreePath *tree_path,
- GtkTreeViewColumn *tree_column,
- gpointer user_data)
-{
- _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
-}
-
-static void
-filter_combo_changed_cb (GtkComboBox *combo_box,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl;
- gint new_index;
- GtkRecentFilter *filter;
-
- impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- new_index = gtk_combo_box_get_active (combo_box);
- filter = g_slist_nth_data (impl->priv->filters, new_index);
-
- set_current_filter (impl, filter);
-}
-
-static GIcon *
-get_drag_icon (GtkRecentChooserDefault *impl)
-{
- GtkRecentInfo *info;
- GIcon *gicon = NULL;
-
- g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
-
- info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
- if (info != NULL)
- {
- gicon = gtk_recent_info_get_gicon (info);
- gtk_recent_info_unref (info);
- }
-
- return gicon;
-}
-
-static void
-recent_view_drag_begin_cb (GtkWidget *widget,
- GdkDragContext *context,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- GIcon *icon;
-
- icon = get_drag_icon (impl);
- if (icon)
- {
- gtk_drag_set_icon_gicon (context, icon, 0, 0);
- g_object_unref (icon);
- }
- else
- gtk_drag_set_icon_default (context);
-}
-
-typedef struct
-{
- gchar **uri_list;
- gsize next_pos;
-} DragData;
-
-static void
-append_uri_to_urilist (GtkTreeModel *model,
- GtkTreePath *path,
- GtkTreeIter *iter,
- gpointer user_data)
-{
- DragData *drag_data = (DragData *) user_data;
- gchar *uri = NULL;
- gsize pos;
-
- gtk_tree_model_get (model, iter,
- RECENT_URI_COLUMN, &uri,
- -1);
- g_assert (uri != NULL);
-
- pos = drag_data->next_pos;
- drag_data->uri_list[pos] = g_strdup (uri);
- drag_data->next_pos = pos + 1;
-}
-
-static void
-recent_view_drag_data_get_cb (GtkWidget *widget,
- GdkDragContext *context,
- GtkSelectionData *selection_data,
- guint info,
- guint32 time_,
- gpointer data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (data);
- DragData drag_data;
- gsize n_uris;
-
- n_uris = gtk_tree_selection_count_selected_rows (impl->priv->selection);
- if (n_uris == 0)
- return;
-
- drag_data.uri_list = g_new0 (gchar *, n_uris + 1);
- drag_data.next_pos = 0;
-
- gtk_tree_selection_selected_foreach (impl->priv->selection,
- append_uri_to_urilist,
- &drag_data);
-
- gtk_selection_data_set_uris (selection_data, drag_data.uri_list);
-
- g_strfreev (drag_data.uri_list);
-}
-
-static gboolean
-recent_view_query_tooltip_cb (GtkWidget *widget,
- gint x,
- gint y,
- gboolean keyboard_tip,
- GtkTooltip *tooltip,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = user_data;
- GtkTreeView *tree_view;
- GtkTreeIter iter;
- GtkTreePath *path = NULL;
- GtkRecentInfo *info = NULL;
- gchar *uri_display;
-
- if (!impl->priv->show_tips)
- return FALSE;
-
- tree_view = GTK_TREE_VIEW (impl->priv->recent_view);
-
- gtk_tree_view_get_tooltip_context (tree_view,
- &x, &y,
- keyboard_tip,
- NULL, &path, NULL);
- if (!path)
- return FALSE;
-
- if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (impl->priv->recent_store), &iter, path))
- {
- gtk_tree_path_free (path);
- return FALSE;
- }
-
- gtk_tree_model_get (GTK_TREE_MODEL (impl->priv->recent_store), &iter,
- RECENT_INFO_COLUMN, &info,
- -1);
-
- uri_display = gtk_recent_info_get_uri_display (info);
-
- gtk_tooltip_set_text (tooltip, uri_display);
- gtk_tree_view_set_tooltip_row (tree_view, tooltip, path);
-
- g_free (uri_display);
- gtk_tree_path_free (path);
- gtk_recent_info_unref (info);
-
- return TRUE;
-}
-
-static void
-remove_selected_from_list (GtkRecentChooserDefault *impl)
-{
- gchar *uri;
- GError *err;
-
- if (impl->priv->select_multiple)
- return;
-
- uri = gtk_recent_chooser_get_current_uri (GTK_RECENT_CHOOSER (impl));
- if (!uri)
- return;
-
- err = NULL;
- if (!gtk_recent_manager_remove_item (impl->priv->manager, uri, &err))
- {
- gchar *msg;
-
- msg = g_strdup (_("Could not remove item"));
- error_message (impl, msg, err->message);
-
- g_free (msg);
- g_error_free (err);
- }
-
- g_free (uri);
-}
-
-static void
-copy_activated_cb (GtkMenuItem *menu_item,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- GtkRecentInfo *info;
- gchar *utf8_uri;
-
- info = gtk_recent_chooser_get_current_item (GTK_RECENT_CHOOSER (impl));
- if (!info)
- return;
-
- utf8_uri = gtk_recent_info_get_uri_display (info);
-
- gdk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (impl)),
- utf8_uri);
-
- gtk_recent_info_unref (info);
- g_free (utf8_uri);
-}
-
-static void
-remove_all_activated_cb (GtkMenuItem *menu_item,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- GError *err = NULL;
-
- gtk_recent_manager_purge_items (impl->priv->manager, &err);
- if (err)
- {
- gchar *msg;
-
- msg = g_strdup (_("Could not clear list"));
-
- error_message (impl, msg, err->message);
-
- g_free (msg);
- g_error_free (err);
- }
-}
-
-static void
-remove_item_activated_cb (GtkMenuItem *menu_item,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- remove_selected_from_list (impl);
-}
-
-static void
-show_private_toggled_cb (GtkCheckMenuItem *menu_item,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- g_object_set (G_OBJECT (impl),
- "show-private", gtk_check_menu_item_get_active (menu_item),
- NULL);
-}
-
-static void
-recent_popup_menu_detach_cb (GtkWidget *attach_widget,
- GtkMenu *menu)
-{
- GtkRecentChooserDefault *impl;
-
- impl = g_object_get_data (G_OBJECT (attach_widget), "GtkRecentChooserDefault");
- g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
-
- impl->priv->recent_popup_menu = NULL;
- impl->priv->recent_popup_menu_remove_item = NULL;
- impl->priv->recent_popup_menu_copy_item = NULL;
- impl->priv->recent_popup_menu_clear_item = NULL;
- impl->priv->recent_popup_menu_show_private_item = NULL;
-}
-
-static void
-recent_view_menu_ensure_state (GtkRecentChooserDefault *impl)
-{
- gint count;
-
- g_assert (GTK_IS_RECENT_CHOOSER_DEFAULT (impl));
- g_assert (impl->priv->recent_popup_menu != NULL);
-
- if (!impl->priv->manager)
- count = 0;
- else
- g_object_get (G_OBJECT (impl->priv->manager), "size", &count, NULL);
-
- if (count == 0)
- {
- gtk_widget_set_sensitive (impl->priv->recent_popup_menu_remove_item, FALSE);
- gtk_widget_set_sensitive (impl->priv->recent_popup_menu_copy_item, FALSE);
- gtk_widget_set_sensitive (impl->priv->recent_popup_menu_clear_item, FALSE);
- gtk_widget_set_sensitive (impl->priv->recent_popup_menu_show_private_item, FALSE);
- }
-}
-
-static void
-recent_view_menu_build (GtkRecentChooserDefault *impl)
-{
- GtkWidget *item;
-
- if (impl->priv->recent_popup_menu)
- {
- recent_view_menu_ensure_state (impl);
-
- return;
- }
-
- impl->priv->recent_popup_menu = gtk_menu_new ();
- gtk_menu_attach_to_widget (GTK_MENU (impl->priv->recent_popup_menu),
- impl->priv->recent_view,
- recent_popup_menu_detach_cb);
-
- item = gtk_menu_item_new_with_mnemonic (_("Copy _Location"));
- impl->priv->recent_popup_menu_copy_item = item;
- g_signal_connect (item, "activate",
- G_CALLBACK (copy_activated_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- item = gtk_menu_item_new_with_mnemonic (_("_Remove From List"));
- impl->priv->recent_popup_menu_remove_item = item;
- g_signal_connect (item, "activate",
- G_CALLBACK (remove_item_activated_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- item = gtk_menu_item_new_with_mnemonic (_("_Clear List"));
- impl->priv->recent_popup_menu_clear_item = item;
- g_signal_connect (item, "activate",
- G_CALLBACK (remove_all_activated_cb), impl);
-
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- item = gtk_separator_menu_item_new ();
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- item = gtk_check_menu_item_new_with_mnemonic (_("Show _Private Resources"));
- impl->priv->recent_popup_menu_show_private_item = item;
- gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), impl->priv->show_private);
- g_signal_connect (item, "toggled",
- G_CALLBACK (show_private_toggled_cb), impl);
- gtk_widget_show (item);
- gtk_menu_shell_append (GTK_MENU_SHELL (impl->priv->recent_popup_menu), item);
-
- recent_view_menu_ensure_state (impl);
-}
-
-static void
-recent_view_menu_popup (GtkRecentChooserDefault *impl,
- GdkEventButton *event)
-{
- recent_view_menu_build (impl);
-
- if (event && gdk_event_triggers_context_menu ((GdkEvent *) event))
- gtk_menu_popup_at_pointer (GTK_MENU (impl->priv->recent_popup_menu), (GdkEvent *) event);
- else
- {
- gtk_menu_popup_at_widget (GTK_MENU (impl->priv->recent_popup_menu),
- impl->priv->recent_view,
- GDK_GRAVITY_CENTER,
- GDK_GRAVITY_CENTER,
- (GdkEvent *) event);
-
- gtk_menu_shell_select_first (GTK_MENU_SHELL (impl->priv->recent_popup_menu), FALSE);
- }
-}
-
-static gboolean
-recent_view_popup_menu_cb (GtkWidget *widget,
- gpointer user_data)
-{
- recent_view_menu_popup (GTK_RECENT_CHOOSER_DEFAULT (user_data), NULL);
- return TRUE;
-}
-
-static void
-multi_press_cb (GtkGesture *gesture,
- int n_press,
- double x,
- double y,
- gpointer user_data)
-{
- GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
- GtkTreePath *path;
- GdkEventSequence *sequence;
- const GdkEvent *event;
-
- if (!gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (impl->priv->recent_view),
- x, y, &path,
- NULL, NULL, NULL))
- return;
-
- /* select the path before creating the popup menu */
- gtk_tree_selection_select_path (impl->priv->selection, path);
- gtk_tree_path_free (path);
-
- sequence = gtk_gesture_get_last_updated_sequence (gesture);
- event = gtk_gesture_get_last_event (gesture, sequence);
-
- recent_view_menu_popup (impl, (GdkEventButton *)event);
-}
-
-static void
-set_recent_manager (GtkRecentChooserDefault *impl,
- GtkRecentManager *manager)
-{
- if (impl->priv->manager)
- {
- if (impl->priv->manager_changed_id)
- {
- g_signal_handler_disconnect (impl, impl->priv->manager_changed_id);
- impl->priv->manager_changed_id = 0;
- }
-
- impl->priv->manager = NULL;
- }
-
- if (manager)
- impl->priv->manager = manager;
- else
- impl->priv->manager = gtk_recent_manager_get_default ();
-
- if (impl->priv->manager)
- {
- impl->priv->manager_changed_id = g_signal_connect (impl->priv->manager, "changed",
- G_CALLBACK (recent_manager_changed_cb),
- impl);
- }
-}
-
-GtkWidget *
-_gtk_recent_chooser_default_new (GtkRecentManager *manager)
-{
- return g_object_new (GTK_TYPE_RECENT_CHOOSER_DEFAULT,
- "recent-manager", manager,
- NULL);
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserdefault.h
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_DEFAULT_H__
-#define __GTK_RECENT_CHOOSER_DEFAULT_H__
-
-#include <gtk/gtkwidget.h>
-
-G_BEGIN_DECLS
-
-
-#define GTK_TYPE_RECENT_CHOOSER_DEFAULT (_gtk_recent_chooser_default_get_type ())
-#define GTK_RECENT_CHOOSER_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_DEFAULT, GtkRecentChooserDefault))
-#define GTK_IS_RECENT_CHOOSER_DEFAULT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_DEFAULT))
-
-
-typedef struct _GtkRecentChooserDefault GtkRecentChooserDefault;
-
-GType _gtk_recent_chooser_default_get_type (void) G_GNUC_CONST;
-GtkWidget *_gtk_recent_chooser_default_new (GtkRecentManager *recent_manager);
-
-
-G_END_DECLS
-
-#endif /* __GTK_RECENT_CHOOSER_DEFAULT_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserdialog.c: Recent files selector dialog
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtkrecentchooserdialog.h"
-#include "gtkrecentchooserwidget.h"
-#include "gtkrecentchooserutils.h"
-#include "gtkrecentmanager.h"
-#include "gtktypebuiltins.h"
-#include "gtksettings.h"
-#include "gtkdialogprivate.h"
-#include "gtkbox.h"
-
-#include <stdarg.h>
-
-
-/**
- * SECTION:gtkrecentchooserdialog
- * @Short_description: Displays recently used files in a dialog
- * @Title: GtkRecentChooserDialog
- * @See_also:#GtkRecentChooser, #GtkDialog
- *
- * #GtkRecentChooserDialog is a dialog box suitable for displaying the recently
- * used documents. This widgets works by putting a #GtkRecentChooserWidget inside
- * a #GtkDialog. It exposes the #GtkRecentChooserIface interface, so you can use
- * all the #GtkRecentChooser functions on the recent chooser dialog as well as
- * those for #GtkDialog.
- *
- * Note that #GtkRecentChooserDialog does not have any methods of its own.
- * Instead, you should use the functions that work on a #GtkRecentChooser.
- *
- * ## Typical usage ## {#gtkrecentchooser-typical-usage}
- *
- * In the simplest of cases, you can use the following code to use
- * a #GtkRecentChooserDialog to select a recently used file:
- *
- * |[<!-- language="C" -->
- * GtkWidget *dialog;
- * gint res;
- *
- * dialog = gtk_recent_chooser_dialog_new ("Recent Documents",
- * parent_window,
- * _("_Cancel"),
- * GTK_RESPONSE_CANCEL,
- * _("_Open"),
- * GTK_RESPONSE_ACCEPT,
- * NULL);
- *
- * res = gtk_dialog_run (GTK_DIALOG (dialog));
- * if (res == GTK_RESPONSE_ACCEPT)
- * {
- * GtkRecentInfo *info;
- * GtkRecentChooser *chooser = GTK_RECENT_CHOOSER (dialog);
- *
- * info = gtk_recent_chooser_get_current_item (chooser);
- * open_file (gtk_recent_info_get_uri (info));
- * gtk_recent_info_unref (info);
- * }
- *
- * gtk_widget_destroy (dialog);
- * ]|
- *
- * Recently used files are supported since GTK+ 2.10.
- */
-
-
-struct _GtkRecentChooserDialogPrivate
-{
- GtkRecentManager *manager;
-
- GtkWidget *chooser;
-};
-
-#define GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE(obj) (GTK_RECENT_CHOOSER_DIALOG (obj)->priv)
-
-static void gtk_recent_chooser_dialog_finalize (GObject *object);
-
-static void gtk_recent_chooser_dialog_constructed (GObject *object);
-
-static void gtk_recent_chooser_dialog_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_recent_chooser_dialog_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserDialog,
- gtk_recent_chooser_dialog,
- GTK_TYPE_DIALOG,
- G_ADD_PRIVATE (GtkRecentChooserDialog)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
- _gtk_recent_chooser_delegate_iface_init))
-
-static void
-gtk_recent_chooser_dialog_class_init (GtkRecentChooserDialogClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->set_property = gtk_recent_chooser_dialog_set_property;
- gobject_class->get_property = gtk_recent_chooser_dialog_get_property;
- gobject_class->constructed = gtk_recent_chooser_dialog_constructed;
- gobject_class->finalize = gtk_recent_chooser_dialog_finalize;
-
- _gtk_recent_chooser_install_properties (gobject_class);
-}
-
-static void
-gtk_recent_chooser_dialog_init (GtkRecentChooserDialog *dialog)
-{
- GtkRecentChooserDialogPrivate *priv;
- GtkWidget *content_area;
- GtkDialog *rc_dialog = GTK_DIALOG (dialog);
-
- priv = gtk_recent_chooser_dialog_get_instance_private (dialog);
- dialog->priv = priv;
- gtk_dialog_set_use_header_bar_from_setting (GTK_DIALOG (dialog));
-
- content_area = gtk_dialog_get_content_area (rc_dialog);
-
- gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
-}
-
-/* we intercept the GtkRecentChooser::item_activated signal and try to
- * make the dialog emit a valid response signal
- */
-static void
-gtk_recent_chooser_item_activated_cb (GtkRecentChooser *chooser,
- gpointer user_data)
-{
- GtkDialog *rc_dialog;
- GtkRecentChooserDialog *dialog;
- GtkWidget *action_area;
- GList *children, *l;
-
- dialog = GTK_RECENT_CHOOSER_DIALOG (user_data);
- rc_dialog = GTK_DIALOG (dialog);
-
- if (gtk_window_activate_default (GTK_WINDOW (dialog)))
- return;
-
- action_area = gtk_dialog_get_action_area (rc_dialog);
- children = gtk_container_get_children (GTK_CONTAINER (action_area));
-
- for (l = children; l; l = l->next)
- {
- GtkWidget *widget;
- gint response_id;
-
- widget = GTK_WIDGET (l->data);
- response_id = gtk_dialog_get_response_for_widget (rc_dialog, widget);
-
- if (response_id == GTK_RESPONSE_ACCEPT ||
- response_id == GTK_RESPONSE_OK ||
- response_id == GTK_RESPONSE_YES ||
- response_id == GTK_RESPONSE_APPLY)
- {
- g_list_free (children);
-
- gtk_dialog_response (GTK_DIALOG (dialog), response_id);
-
- return;
- }
- }
-
- g_list_free (children);
-}
-
-static void
-gtk_recent_chooser_dialog_constructed (GObject *object)
-{
- GtkRecentChooserDialogPrivate *priv;
- GtkWidget *content_area;
-
- G_OBJECT_CLASS (gtk_recent_chooser_dialog_parent_class)->constructed (object);
- priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
-
- if (priv->manager)
- priv->chooser = g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
- "recent-manager", priv->manager,
- NULL);
- else
- priv->chooser = g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
-
- g_signal_connect (priv->chooser, "item-activated",
- G_CALLBACK (gtk_recent_chooser_item_activated_cb),
- object);
-
- content_area = gtk_dialog_get_content_area (GTK_DIALOG (object));
-
- gtk_box_pack_start (GTK_BOX (content_area),
- priv->chooser);
-
- _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (object),
- GTK_RECENT_CHOOSER (priv->chooser));
-}
-
-static void
-gtk_recent_chooser_dialog_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserDialogPrivate *priv;
-
- priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
-
- switch (prop_id)
- {
- case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
- priv->manager = g_value_get_object (value);
- break;
- default:
- g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
- break;
- }
-}
-
-static void
-gtk_recent_chooser_dialog_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserDialogPrivate *priv;
-
- priv = GTK_RECENT_CHOOSER_DIALOG_GET_PRIVATE (object);
-
- g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
-}
-
-static void
-gtk_recent_chooser_dialog_finalize (GObject *object)
-{
- GtkRecentChooserDialog *dialog = GTK_RECENT_CHOOSER_DIALOG (object);
-
- dialog->priv->manager = NULL;
-
- G_OBJECT_CLASS (gtk_recent_chooser_dialog_parent_class)->finalize (object);
-}
-
-static GtkWidget *
-gtk_recent_chooser_dialog_new_valist (const gchar *title,
- GtkWindow *parent,
- GtkRecentManager *manager,
- const gchar *first_button_text,
- va_list varargs)
-{
- GtkWidget *result;
- const char *button_text = first_button_text;
- gint response_id;
-
- result = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
- "title", title,
- "recent-manager", manager,
- NULL);
-
- if (parent)
- gtk_window_set_transient_for (GTK_WINDOW (result), parent);
-
- while (button_text)
- {
- response_id = va_arg (varargs, gint);
- gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
- button_text = va_arg (varargs, const gchar *);
- }
-
- return result;
-}
-
-/**
- * gtk_recent_chooser_dialog_new:
- * @title: (allow-none): Title of the dialog, or %NULL
- * @parent: (allow-none): Transient parent of the dialog, or %NULL,
- * @first_button_text: (allow-none): text to go in the first button, or %NULL
- * @...: response ID for the first button, then additional (button, id)
- * pairs, ending with %NULL
- *
- * Creates a new #GtkRecentChooserDialog. This function is analogous to
- * gtk_dialog_new_with_buttons().
- *
- * Returns: a new #GtkRecentChooserDialog
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_dialog_new (const gchar *title,
- GtkWindow *parent,
- const gchar *first_button_text,
- ...)
-{
- GtkWidget *result;
- va_list varargs;
-
- va_start (varargs, first_button_text);
- result = gtk_recent_chooser_dialog_new_valist (title,
- parent,
- NULL,
- first_button_text,
- varargs);
- va_end (varargs);
-
- return result;
-}
-
-/**
- * gtk_recent_chooser_dialog_new_for_manager:
- * @title: (allow-none): Title of the dialog, or %NULL
- * @parent: (allow-none): Transient parent of the dialog, or %NULL,
- * @manager: a #GtkRecentManager
- * @first_button_text: (allow-none): text to go in the first button, or %NULL
- * @...: response ID for the first button, then additional (button, id)
- * pairs, ending with %NULL
- *
- * Creates a new #GtkRecentChooserDialog with a specified recent manager.
- *
- * This is useful if you have implemented your own recent manager, or if you
- * have a customized instance of a #GtkRecentManager object.
- *
- * Returns: a new #GtkRecentChooserDialog
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_dialog_new_for_manager (const gchar *title,
- GtkWindow *parent,
- GtkRecentManager *manager,
- const gchar *first_button_text,
- ...)
-{
- GtkWidget *result;
- va_list varargs;
-
- va_start (varargs, first_button_text);
- result = gtk_recent_chooser_dialog_new_valist (title,
- parent,
- manager,
- first_button_text,
- varargs);
- va_end (varargs);
-
- return result;
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserdialog.h: Recent files selector dialog
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_DIALOG_H__
-#define __GTK_RECENT_CHOOSER_DIALOG_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkdialog.h>
-#include <gtk/gtkrecentchooser.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RECENT_CHOOSER_DIALOG (gtk_recent_chooser_dialog_get_type ())
-#define GTK_RECENT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialog))
-#define GTK_IS_RECENT_CHOOSER_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG))
-#define GTK_RECENT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialogClass))
-#define GTK_IS_RECENT_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_DIALOG))
-#define GTK_RECENT_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_DIALOG, GtkRecentChooserDialogClass))
-
-typedef struct _GtkRecentChooserDialog GtkRecentChooserDialog;
-typedef struct _GtkRecentChooserDialogClass GtkRecentChooserDialogClass;
-
-typedef struct _GtkRecentChooserDialogPrivate GtkRecentChooserDialogPrivate;
-
-
-struct _GtkRecentChooserDialog
-{
- GtkDialog parent_instance;
-
- /*< private >*/
- GtkRecentChooserDialogPrivate *priv;
-};
-
-struct _GtkRecentChooserDialogClass
-{
- GtkDialogClass parent_class;
-
- /* Padding for future expansion */
- void (*_gtk_reserved1) (void);
- void (*_gtk_reserved2) (void);
- void (*_gtk_reserved3) (void);
- void (*_gtk_reserved4) (void);
-};
-
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_chooser_dialog_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_dialog_new (const gchar *title,
- GtkWindow *parent,
- const gchar *first_button_text,
- ...) G_GNUC_NULL_TERMINATED;
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_dialog_new_for_manager (const gchar *title,
- GtkWindow *parent,
- GtkRecentManager *manager,
- const gchar *first_button_text,
- ...) G_GNUC_NULL_TERMINATED;
-
-G_END_DECLS
-
-#endif /* __GTK_RECENT_CHOOSER_DIALOG_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchoosermenu.c - Recently used items menu widget
- * Copyright (C) 2005, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <string.h>
-
-#include "gtkrecentmanager.h"
-#include "gtkrecentfilter.h"
-#include "gtkrecentchooser.h"
-#include "gtkrecentchooserutils.h"
-#include "gtkrecentchooserprivate.h"
-#include "gtkrecentchoosermenu.h"
-
-#include "gtkicontheme.h"
-#include "gtkintl.h"
-#include "gtksettings.h"
-#include "gtkmenushell.h"
-#include "gtkmenuitem.h"
-#include "gtkseparatormenuitem.h"
-#include "gtkmenu.h"
-#include "gtkimage.h"
-#include "gtklabel.h"
-#include "gtkbox.h"
-#include "gtktooltip.h"
-#include "gtktypebuiltins.h"
-#include "gtkprivate.h"
-
-/**
- * SECTION:gtkrecentchoosermenu
- * @Short_description: Displays recently used files in a menu
- * @Title: GtkRecentChooserMenu
- * @See_also:#GtkRecentChooser
- *
- * #GtkRecentChooserMenu is a widget suitable for displaying recently used files
- * inside a menu. It can be used to set a sub-menu of a #GtkMenuItem using
- * gtk_menu_item_set_submenu(), or as the menu of a #GtkMenuToolButton.
- *
- * Note that #GtkRecentChooserMenu does not have any methods of its own. Instead,
- * you should use the functions that work on a #GtkRecentChooser.
- *
- * Note also that #GtkRecentChooserMenu does not support multiple filters, as it
- * has no way to let the user choose between them as the #GtkRecentChooserWidget
- * and #GtkRecentChooserDialog widgets do. Thus using gtk_recent_chooser_add_filter()
- * on a #GtkRecentChooserMenu widget will yield the same effects as using
- * gtk_recent_chooser_set_filter(), replacing any currently set filter
- * with the supplied filter; gtk_recent_chooser_remove_filter() will remove
- * any currently set #GtkRecentFilter object and will unset the current filter;
- * gtk_recent_chooser_list_filters() will return a list containing a single
- * #GtkRecentFilter object.
- *
- * Recently used files are supported since GTK+ 2.10.
- */
-
-
-struct _GtkRecentChooserMenuPrivate
-{
- /* the recent manager object */
- GtkRecentManager *manager;
-
- /* max size of the menu item label */
- gint label_width;
-
- gint first_recent_item_pos;
- GtkWidget *placeholder;
-
- /* RecentChooser properties */
- gint limit;
- guint show_private : 1;
- guint show_not_found : 1;
- guint show_tips : 1;
- guint show_icons : 1;
- guint local_only : 1;
-
- guint show_numbers : 1;
-
- GtkRecentSortType sort_type;
- GtkRecentSortFunc sort_func;
- gpointer sort_data;
- GDestroyNotify sort_data_destroy;
-
- GSList *filters;
- GtkRecentFilter *current_filter;
-
- guint local_manager : 1;
- gulong manager_changed_id;
-
- gulong populate_id;
-};
-
-enum {
- PROP_0,
- PROP_SHOW_NUMBERS,
-};
-
-
-#define FALLBACK_ITEM_LIMIT 10
-#define DEFAULT_LABEL_WIDTH 30
-
-
-static void gtk_recent_chooser_menu_finalize (GObject *object);
-static void gtk_recent_chooser_menu_dispose (GObject *object);
-static void gtk_recent_chooser_menu_constructed (GObject *object);
-
-static void gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface);
-
-static void gtk_recent_chooser_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_recent_chooser_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-
-static gboolean gtk_recent_chooser_menu_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static gchar * gtk_recent_chooser_menu_get_current_uri (GtkRecentChooser *chooser);
-static gboolean gtk_recent_chooser_menu_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static void gtk_recent_chooser_menu_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri);
-static void gtk_recent_chooser_menu_select_all (GtkRecentChooser *chooser);
-static void gtk_recent_chooser_menu_unselect_all (GtkRecentChooser *chooser);
-static GList * gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser);
-static GtkRecentManager *gtk_recent_chooser_menu_get_recent_manager (GtkRecentChooser *chooser);
-static void gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy);
-static void gtk_recent_chooser_menu_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static void gtk_recent_chooser_menu_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static GSList * gtk_recent_chooser_menu_list_filters (GtkRecentChooser *chooser);
-static void gtk_recent_chooser_menu_set_current_filter (GtkRecentChooserMenu *menu,
- GtkRecentFilter *filter);
-
-static void gtk_recent_chooser_menu_populate (GtkRecentChooserMenu *menu);
-static void gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
- gboolean show_tips);
-
-static void set_recent_manager (GtkRecentChooserMenu *menu,
- GtkRecentManager *manager);
-
-static void item_activate_cb (GtkWidget *widget,
- gpointer user_data);
-static void manager_changed_cb (GtkRecentManager *manager,
- gpointer user_data);
-
-G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserMenu,
- gtk_recent_chooser_menu,
- GTK_TYPE_MENU,
- G_ADD_PRIVATE (GtkRecentChooserMenu)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
- gtk_recent_chooser_iface_init))
-
-static void
-gtk_recent_chooser_iface_init (GtkRecentChooserIface *iface)
-{
- iface->set_current_uri = gtk_recent_chooser_menu_set_current_uri;
- iface->get_current_uri = gtk_recent_chooser_menu_get_current_uri;
- iface->select_uri = gtk_recent_chooser_menu_select_uri;
- iface->unselect_uri = gtk_recent_chooser_menu_unselect_uri;
- iface->select_all = gtk_recent_chooser_menu_select_all;
- iface->unselect_all = gtk_recent_chooser_menu_unselect_all;
- iface->get_items = gtk_recent_chooser_menu_get_items;
- iface->get_recent_manager = gtk_recent_chooser_menu_get_recent_manager;
- iface->set_sort_func = gtk_recent_chooser_menu_set_sort_func;
- iface->add_filter = gtk_recent_chooser_menu_add_filter;
- iface->remove_filter = gtk_recent_chooser_menu_remove_filter;
- iface->list_filters = gtk_recent_chooser_menu_list_filters;
-}
-
-static void
-gtk_recent_chooser_menu_class_init (GtkRecentChooserMenuClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->constructed = gtk_recent_chooser_menu_constructed;
- gobject_class->dispose = gtk_recent_chooser_menu_dispose;
- gobject_class->finalize = gtk_recent_chooser_menu_finalize;
- gobject_class->set_property = gtk_recent_chooser_menu_set_property;
- gobject_class->get_property = gtk_recent_chooser_menu_get_property;
-
- _gtk_recent_chooser_install_properties (gobject_class);
-
- /**
- * GtkRecentChooserMenu:show-numbers:
- *
- * Whether the first ten items in the menu should be prepended by
- * a number acting as a unique mnemonic.
- *
- * Since: 2.10
- */
- g_object_class_install_property (gobject_class,
- PROP_SHOW_NUMBERS,
- g_param_spec_boolean ("show-numbers",
- P_("Show Numbers"),
- P_("Whether the items should be displayed with a number"),
- FALSE,
- GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
-}
-
-static void
-gtk_recent_chooser_menu_init (GtkRecentChooserMenu *menu)
-{
- GtkRecentChooserMenuPrivate *priv;
-
- menu->priv = gtk_recent_chooser_menu_get_instance_private (menu);
- priv = menu->priv;
-
- priv->show_icons= TRUE;
- priv->show_numbers = FALSE;
- priv->show_tips = FALSE;
- priv->show_not_found = TRUE;
- priv->show_private = FALSE;
- priv->local_only = TRUE;
-
- priv->limit = FALLBACK_ITEM_LIMIT;
- priv->sort_type = GTK_RECENT_SORT_NONE;
- priv->label_width = DEFAULT_LABEL_WIDTH;
-
- priv->first_recent_item_pos = -1;
- priv->placeholder = NULL;
-
- priv->current_filter = NULL;
-}
-
-static void
-gtk_recent_chooser_menu_finalize (GObject *object)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- priv->manager = NULL;
-
- if (priv->sort_data_destroy)
- {
- priv->sort_data_destroy (priv->sort_data);
- priv->sort_data_destroy = NULL;
- }
-
- priv->sort_data = NULL;
- priv->sort_func = NULL;
-
- G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->finalize (object);
-}
-
-static void
-gtk_recent_chooser_menu_dispose (GObject *object)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- if (priv->manager_changed_id)
- {
- if (priv->manager)
- g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
-
- priv->manager_changed_id = 0;
- }
-
- if (priv->populate_id)
- {
- g_source_remove (priv->populate_id);
- priv->populate_id = 0;
- }
-
- if (priv->current_filter)
- {
- g_object_unref (priv->current_filter);
- priv->current_filter = NULL;
- }
-
- G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->dispose (object);
-}
-
-static void
-gtk_recent_chooser_menu_constructed (GObject *object)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- G_OBJECT_CLASS (gtk_recent_chooser_menu_parent_class)->constructed (object);
-
- g_assert (priv->manager);
-
- /* we create a placeholder menuitem, to be used in case
- * the menu is empty. this placeholder will stay around
- * for the entire lifetime of the menu, and we just hide it
- * when it's not used. we have to do this, and do it here,
- * because we need a marker for the beginning of the recent
- * items list, so that we can insert the new items at the
- * right place when idly populating the menu in case the
- * user appended or prepended custom menu items to the
- * recent chooser menu widget.
- */
- priv->placeholder = gtk_menu_item_new_with_label (_("No items found"));
- gtk_widget_set_sensitive (priv->placeholder, FALSE);
- g_object_set_data (G_OBJECT (priv->placeholder),
- "gtk-recent-menu-placeholder",
- GINT_TO_POINTER (TRUE));
-
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), priv->placeholder, 0);
- gtk_widget_show (priv->placeholder);
-
- /* (re)populate the menu */
- gtk_recent_chooser_menu_populate (menu);
-}
-
-static void
-gtk_recent_chooser_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- switch (prop_id)
- {
- case PROP_SHOW_NUMBERS:
- if (priv->show_numbers != g_value_get_boolean (value))
- {
- priv->show_numbers = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
- set_recent_manager (menu, g_value_get_object (value));
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- if (priv->show_private != g_value_get_boolean (value))
- {
- priv->show_private = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- if (priv->show_not_found != g_value_get_boolean (value))
- {
- priv->show_not_found = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- gtk_recent_chooser_menu_set_show_tips (menu, g_value_get_boolean (value));
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- if (priv->show_icons != g_value_get_boolean (value))
- {
- priv->show_icons = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
- g_warning ("%s: Choosers of type '%s' do not support selecting multiple items.",
- G_STRFUNC,
- G_OBJECT_TYPE_NAME (object));
- break;
- case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- if (priv->local_only != g_value_get_boolean (value))
- {
- priv->local_only = g_value_get_boolean (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_LIMIT:
- if (priv->limit != g_value_get_int (value))
- {
- priv->limit = g_value_get_int (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- if (priv->sort_type != g_value_get_enum (value))
- {
- priv->sort_type = g_value_get_enum (value);
- g_object_notify_by_pspec (object, pspec);
- }
- break;
- case GTK_RECENT_CHOOSER_PROP_FILTER:
- gtk_recent_chooser_menu_set_current_filter (menu, g_value_get_object (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-gtk_recent_chooser_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (object);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- switch (prop_id)
- {
- case PROP_SHOW_NUMBERS:
- g_value_set_boolean (value, priv->show_numbers);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_TIPS:
- g_value_set_boolean (value, priv->show_tips);
- break;
- case GTK_RECENT_CHOOSER_PROP_LIMIT:
- g_value_set_int (value, priv->limit);
- break;
- case GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY:
- g_value_set_boolean (value, priv->local_only);
- break;
- case GTK_RECENT_CHOOSER_PROP_SORT_TYPE:
- g_value_set_enum (value, priv->sort_type);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE:
- g_value_set_boolean (value, priv->show_private);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND:
- g_value_set_boolean (value, priv->show_not_found);
- break;
- case GTK_RECENT_CHOOSER_PROP_SHOW_ICONS:
- g_value_set_boolean (value, priv->show_icons);
- break;
- case GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE:
- g_value_set_boolean (value, FALSE);
- break;
- case GTK_RECENT_CHOOSER_PROP_FILTER:
- g_value_set_object (value, priv->current_filter);
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static gboolean
-gtk_recent_chooser_menu_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GList *children, *l;
- GtkWidget *menu_item = NULL;
- gboolean found = FALSE;
- gint i = 0;
-
- children = gtk_container_get_children (GTK_CONTAINER (menu));
-
- for (l = children; l != NULL; l = l->next, i++)
- {
- GtkRecentInfo *info;
-
- menu_item = GTK_WIDGET (l->data);
-
- info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
- if (!info)
- continue;
-
- if (strcmp (uri, gtk_recent_info_get_uri (info)) == 0)
- {
- gtk_menu_set_active (GTK_MENU (menu), i);
- found = TRUE;
-
- break;
- }
- }
-
- g_list_free (children);
-
- if (!found)
- {
- g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
- GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
- _("No recently used resource found with URI “%s”"),
- uri);
- }
-
- return found;
-}
-
-static gchar *
-gtk_recent_chooser_menu_get_current_uri (GtkRecentChooser *chooser)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GtkWidget *menu_item;
- GtkRecentInfo *info;
-
- menu_item = gtk_menu_get_active (GTK_MENU (menu));
- if (!menu_item)
- return NULL;
-
- info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
- if (!info)
- return NULL;
-
- return g_strdup (gtk_recent_info_get_uri (info));
-}
-
-static gboolean
-gtk_recent_chooser_menu_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GList *children, *l;
- GtkWidget *menu_item = NULL;
- gboolean found = FALSE;
-
- children = gtk_container_get_children (GTK_CONTAINER (menu));
- for (l = children; l != NULL; l = l->next)
- {
- GtkRecentInfo *info;
-
- menu_item = GTK_WIDGET (l->data);
-
- info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
- if (!info)
- continue;
-
- if (0 == strcmp (uri, gtk_recent_info_get_uri (info)))
- found = TRUE;
- }
-
- g_list_free (children);
-
- if (!found)
- {
- g_set_error (error, GTK_RECENT_CHOOSER_ERROR,
- GTK_RECENT_CHOOSER_ERROR_NOT_FOUND,
- _("No recently used resource found with URI “%s”"),
- uri);
- return FALSE;
- }
- else
- {
- gtk_menu_shell_select_item (GTK_MENU_SHELL (menu), menu_item);
-
- return TRUE;
- }
-}
-
-static void
-gtk_recent_chooser_menu_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
-
- gtk_menu_shell_deselect (GTK_MENU_SHELL (menu));
-}
-
-static void
-gtk_recent_chooser_menu_select_all (GtkRecentChooser *chooser)
-{
- g_warning ("This function is not implemented for "
- "widgets of class '%s'",
- g_type_name (G_OBJECT_TYPE (chooser)));
-}
-
-static void
-gtk_recent_chooser_menu_unselect_all (GtkRecentChooser *chooser)
-{
- g_warning ("This function is not implemented for "
- "widgets of class '%s'",
- g_type_name (G_OBJECT_TYPE (chooser)));
-}
-
-static void
-gtk_recent_chooser_menu_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- if (priv->sort_data_destroy)
- {
- priv->sort_data_destroy (priv->sort_data);
- priv->sort_data_destroy = NULL;
- }
-
- priv->sort_func = NULL;
- priv->sort_data = NULL;
- priv->sort_data_destroy = NULL;
-
- if (sort_func)
- {
- priv->sort_func = sort_func;
- priv->sort_data = sort_data;
- priv->sort_data_destroy = data_destroy;
- }
-}
-
-static GList *
-gtk_recent_chooser_menu_get_items (GtkRecentChooser *chooser)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (chooser);
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- return _gtk_recent_chooser_get_items (chooser,
- priv->current_filter,
- priv->sort_func,
- priv->sort_data);
-}
-
-static GtkRecentManager *
-gtk_recent_chooser_menu_get_recent_manager (GtkRecentChooser *chooser)
-{
- GtkRecentChooserMenuPrivate *priv;
-
- priv = GTK_RECENT_CHOOSER_MENU (chooser)->priv;
-
- return priv->manager;
-}
-
-static void
-gtk_recent_chooser_menu_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- GtkRecentChooserMenu *menu;
-
- menu = GTK_RECENT_CHOOSER_MENU (chooser);
-
- gtk_recent_chooser_menu_set_current_filter (menu, filter);
-}
-
-static void
-gtk_recent_chooser_menu_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- GtkRecentChooserMenu *menu;
-
- menu = GTK_RECENT_CHOOSER_MENU (chooser);
-
- if (filter == menu->priv->current_filter)
- {
- g_object_unref (menu->priv->current_filter);
- menu->priv->current_filter = NULL;
-
- g_object_notify (G_OBJECT (menu), "filter");
- }
-}
-
-static GSList *
-gtk_recent_chooser_menu_list_filters (GtkRecentChooser *chooser)
-{
- GtkRecentChooserMenu *menu;
- GSList *retval = NULL;
-
- menu = GTK_RECENT_CHOOSER_MENU (chooser);
-
- if (menu->priv->current_filter)
- retval = g_slist_prepend (retval, menu->priv->current_filter);
-
- return retval;
-}
-
-static void
-gtk_recent_chooser_menu_set_current_filter (GtkRecentChooserMenu *menu,
- GtkRecentFilter *filter)
-{
- GtkRecentChooserMenuPrivate *priv;
-
- priv = menu->priv;
-
- if (priv->current_filter)
- g_object_unref (G_OBJECT (priv->current_filter));
-
- priv->current_filter = filter;
-
- if (priv->current_filter)
- g_object_ref_sink (priv->current_filter);
-
- gtk_recent_chooser_menu_populate (menu);
-
- g_object_notify (G_OBJECT (menu), "filter");
-}
-
-/* taken from libeel/eel-strings.c */
-static gchar *
-escape_underscores (const gchar *string)
-{
- gint underscores;
- const gchar *p;
- gchar *q;
- gchar *escaped;
-
- if (!string)
- return NULL;
-
- underscores = 0;
- for (p = string; *p != '\0'; p++)
- underscores += (*p == '_');
-
- if (underscores == 0)
- return g_strdup (string);
-
- escaped = g_new (char, strlen (string) + underscores + 1);
- for (p = string, q = escaped; *p != '\0'; p++, q++)
- {
- /* Add an extra underscore. */
- if (*p == '_')
- *q++ = '_';
-
- *q = *p;
- }
-
- *q = '\0';
-
- return escaped;
-}
-
-static void
-gtk_recent_chooser_menu_add_tip (GtkRecentChooserMenu *menu,
- GtkRecentInfo *info,
- GtkWidget *item)
-{
- GtkRecentChooserMenuPrivate *priv;
- gchar *path;
-
- g_assert (info != NULL);
- g_assert (item != NULL);
-
- priv = menu->priv;
-
- path = gtk_recent_info_get_uri_display (info);
- if (path)
- {
- gchar *tip_text = g_strdup_printf (_("Open “%s”"), path);
-
- gtk_widget_set_tooltip_text (item, tip_text);
- gtk_widget_set_has_tooltip (item, priv->show_tips);
-
- g_free (path);
- g_free (tip_text);
- }
-}
-
-static GtkWidget *
-gtk_recent_chooser_menu_create_item (GtkRecentChooserMenu *menu,
- GtkRecentInfo *info,
- gint count)
-{
- GtkRecentChooserMenuPrivate *priv;
- gchar *text;
- GtkWidget *item, *image, *label;
- GIcon *icon;
- GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-
- g_assert (info != NULL);
-
- priv = menu->priv;
-
- if (priv->show_numbers)
- {
- gchar *name, *escaped;
-
- name = g_strdup (gtk_recent_info_get_display_name (info));
- if (!name)
- name = g_strdup (_("Unknown item"));
-
- escaped = escape_underscores (name);
-
- /* avoid clashing mnemonics */
- if (count <= 10)
- /* This is the label format that is used for the first 10 items
- * in a recent files menu. The %d is the number of the item,
- * the %s is the name of the item. Please keep the _ in front
- * of the number to give these menu items a mnemonic.
- */
- text = g_strdup_printf (C_("recent menu label", "_%d. %s"), count, escaped);
- else
- /* This is the format that is used for items in a recent files menu.
- * The %d is the number of the item, the %s is the name of the item.
- */
- text = g_strdup_printf (C_("recent menu label", "%d. %s"), count, escaped);
-
- label = gtk_label_new_with_mnemonic (text);
-
- g_free (escaped);
- g_free (name);
- }
- else
- {
- text = g_strdup (gtk_recent_info_get_display_name (info));
- label = gtk_label_new (text);
- }
-
- g_free (text);
-
- /* ellipsize the menu item label, in case the recent document
- * display name is huge.
- */
- gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END);
- gtk_label_set_max_width_chars (GTK_LABEL (label), priv->label_width);
-
- if (priv->show_icons)
- {
- icon = gtk_recent_info_get_gicon (info);
-
- image = gtk_image_new_from_gicon (icon);
- if (icon)
- g_object_unref (icon);
-
- gtk_container_add (GTK_CONTAINER (box), image);
- }
-
- item = gtk_menu_item_new ();
- gtk_container_add (GTK_CONTAINER (box), label);
- gtk_container_add (GTK_CONTAINER (item), box);
-
- g_signal_connect (item, "activate",
- G_CALLBACK (item_activate_cb),
- menu);
-
- return item;
-}
-
-static void
-gtk_recent_chooser_menu_insert_item (GtkRecentChooserMenu *menu,
- GtkWidget *menuitem,
- gint position)
-{
- GtkRecentChooserMenuPrivate *priv = menu->priv;
- gint real_position;
-
- if (priv->first_recent_item_pos == -1)
- {
- GList *children, *l;
-
- children = gtk_container_get_children (GTK_CONTAINER (menu));
-
- for (real_position = 0, l = children;
- l != NULL;
- real_position += 1, l = l->next)
- {
- GObject *child = l->data;
- gboolean is_placeholder = FALSE;
-
- is_placeholder =
- GPOINTER_TO_INT (g_object_get_data (child, "gtk-recent-menu-placeholder"));
-
- if (is_placeholder)
- break;
- }
-
- g_list_free (children);
- priv->first_recent_item_pos = real_position;
- }
- else
- real_position = priv->first_recent_item_pos;
-
- gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menuitem,
- real_position + position);
- gtk_widget_show (menuitem);
-}
-
-/* removes the items we own from the menu */
-static void
-gtk_recent_chooser_menu_dispose_items (GtkRecentChooserMenu *menu)
-{
- GList *children, *l;
-
- children = gtk_container_get_children (GTK_CONTAINER (menu));
- for (l = children; l != NULL; l = l->next)
- {
- GtkWidget *menu_item = GTK_WIDGET (l->data);
- gboolean has_mark = FALSE;
-
- /* check for our mark, in order to remove just the items we own */
- has_mark =
- GPOINTER_TO_INT (g_object_get_data (G_OBJECT (menu_item), "gtk-recent-menu-mark"));
-
- if (has_mark)
- {
- GtkRecentInfo *info;
-
- /* destroy the attached RecentInfo struct, if found */
- info = g_object_get_data (G_OBJECT (menu_item), "gtk-recent-info");
- if (info)
- g_object_set_data_full (G_OBJECT (menu_item), "gtk-recent-info",
- NULL, NULL);
-
- /* and finally remove the item from the menu */
- gtk_container_remove (GTK_CONTAINER (menu), menu_item);
- }
- }
-
- /* recalculate the position of the first recent item */
- menu->priv->first_recent_item_pos = -1;
-
- g_list_free (children);
-}
-
-typedef struct
-{
- GList *items;
- gint n_items;
- gint loaded_items;
- gint displayed_items;
- GtkRecentChooserMenu *menu;
- GtkWidget *placeholder;
-} MenuPopulateData;
-
-static MenuPopulateData *
-create_menu_populate_data (GtkRecentChooserMenu *menu)
-{
- MenuPopulateData *pdata;
-
- pdata = g_slice_new (MenuPopulateData);
- pdata->items = NULL;
- pdata->n_items = 0;
- pdata->loaded_items = 0;
- pdata->displayed_items = 0;
- pdata->menu = menu;
- pdata->placeholder = g_object_ref (menu->priv->placeholder);
-
- return pdata;
-}
-
-static void
-free_menu_populate_data (MenuPopulateData *pdata)
-{
- if (pdata->placeholder)
- g_object_unref (pdata->placeholder);
- g_slice_free (MenuPopulateData, pdata);
-}
-
-static gboolean
-idle_populate_func (gpointer data)
-{
- MenuPopulateData *pdata;
- GtkRecentChooserMenuPrivate *priv;
- GtkRecentInfo *info;
- gboolean retval;
- GtkWidget *item;
-
- pdata = (MenuPopulateData *) data;
- priv = pdata->menu->priv;
-
- if (!pdata->items)
- {
- pdata->items = gtk_recent_chooser_get_items (GTK_RECENT_CHOOSER (pdata->menu));
- if (!pdata->items)
- {
- /* show the placeholder here */
- gtk_widget_show (pdata->placeholder);
- pdata->displayed_items = 1;
- priv->populate_id = 0;
-
- return FALSE;
- }
- else
- gtk_widget_hide (pdata->placeholder);
-
- pdata->n_items = g_list_length (pdata->items);
- pdata->loaded_items = 0;
- }
-
- info = g_list_nth_data (pdata->items, pdata->loaded_items);
- item = gtk_recent_chooser_menu_create_item (pdata->menu,
- info,
- pdata->displayed_items);
- if (!item)
- goto check_and_return;
-
- gtk_recent_chooser_menu_add_tip (pdata->menu, info, item);
- gtk_recent_chooser_menu_insert_item (pdata->menu, item,
- pdata->displayed_items);
-
- pdata->displayed_items += 1;
-
- /* mark the menu item as one of our own */
- g_object_set_data (G_OBJECT (item),
- "gtk-recent-menu-mark",
- GINT_TO_POINTER (TRUE));
-
- /* attach the RecentInfo object to the menu item, and own a reference
- * to it, so that it will be destroyed with the menu item when it's
- * not needed anymore.
- */
- g_object_set_data_full (G_OBJECT (item), "gtk-recent-info",
- gtk_recent_info_ref (info),
- (GDestroyNotify) gtk_recent_info_unref);
-
-check_and_return:
- pdata->loaded_items += 1;
-
- if (pdata->loaded_items == pdata->n_items)
- {
- g_list_free_full (pdata->items, (GDestroyNotify) gtk_recent_info_unref);
-
- priv->populate_id = 0;
-
- retval = FALSE;
- }
- else
- retval = TRUE;
-
- return retval;
-}
-
-static void
-idle_populate_clean_up (gpointer data)
-{
- MenuPopulateData *pdata = data;
-
- if (pdata->menu->priv->populate_id == 0)
- {
- /* show the placeholder in case no item survived
- * the filtering process in the idle loop
- */
- if (!pdata->displayed_items)
- gtk_widget_show (pdata->placeholder);
- }
-
- free_menu_populate_data (pdata);
-}
-
-static void
-gtk_recent_chooser_menu_populate (GtkRecentChooserMenu *menu)
-{
- MenuPopulateData *pdata;
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- if (priv->populate_id)
- return;
-
- pdata = create_menu_populate_data (menu);
-
- /* remove our menu items first */
- gtk_recent_chooser_menu_dispose_items (menu);
-
- priv->populate_id = gdk_threads_add_idle_full (G_PRIORITY_HIGH_IDLE + 30,
- idle_populate_func,
- pdata,
- idle_populate_clean_up);
- g_source_set_name_by_id (priv->populate_id, "[gtk+] idle_populate_func");
-}
-
-/* bounce activate signal from the recent menu item widget
- * to the recent menu widget
- */
-static void
-item_activate_cb (GtkWidget *widget,
- gpointer user_data)
-{
- GtkRecentChooser *chooser = GTK_RECENT_CHOOSER (user_data);
- GtkRecentInfo *info = g_object_get_data (G_OBJECT (widget), "gtk-recent-info");
-
- gtk_recent_chooser_menu_set_current_uri (chooser, gtk_recent_info_get_uri (info), NULL);
- _gtk_recent_chooser_item_activated (chooser);
-}
-
-/* we force a redraw if the manager changes when we are showing */
-static void
-manager_changed_cb (GtkRecentManager *manager,
- gpointer user_data)
-{
- GtkRecentChooserMenu *menu = GTK_RECENT_CHOOSER_MENU (user_data);
-
- gtk_recent_chooser_menu_populate (menu);
-}
-
-static void
-set_recent_manager (GtkRecentChooserMenu *menu,
- GtkRecentManager *manager)
-{
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- if (priv->manager)
- {
- if (priv->manager_changed_id)
- {
- g_signal_handler_disconnect (priv->manager, priv->manager_changed_id);
- priv->manager_changed_id = 0;
- }
-
- if (priv->populate_id)
- {
- g_source_remove (priv->populate_id);
- priv->populate_id = 0;
- }
-
- priv->manager = NULL;
- }
-
- if (manager)
- priv->manager = manager;
- else
- priv->manager = gtk_recent_manager_get_default ();
-
- if (priv->manager)
- priv->manager_changed_id = g_signal_connect (priv->manager, "changed",
- G_CALLBACK (manager_changed_cb),
- menu);
-}
-
-static void
-foreach_set_shot_tips (GtkWidget *widget,
- gpointer user_data)
-{
- GtkRecentChooserMenu *menu = user_data;
- GtkRecentChooserMenuPrivate *priv = menu->priv;
- gboolean has_mark;
-
- /* toggle the tooltip only on the items we create */
- has_mark =
- GPOINTER_TO_INT (g_object_get_data (G_OBJECT (widget), "gtk-recent-menu-mark"));
-
- if (has_mark)
- gtk_widget_set_has_tooltip (widget, priv->show_tips);
-}
-
-static void
-gtk_recent_chooser_menu_set_show_tips (GtkRecentChooserMenu *menu,
- gboolean show_tips)
-{
- GtkRecentChooserMenuPrivate *priv = menu->priv;
-
- if (priv->show_tips == show_tips)
- return;
-
- priv->show_tips = show_tips;
- gtk_container_foreach (GTK_CONTAINER (menu), foreach_set_shot_tips, menu);
- g_object_notify (G_OBJECT (menu), "show-tips");
-}
-
-/*
- * Public API
- */
-
-/**
- * gtk_recent_chooser_menu_new:
- *
- * Creates a new #GtkRecentChooserMenu widget.
- *
- * This kind of widget shows the list of recently used resources as
- * a menu, each item as a menu item. Each item inside the menu might
- * have an icon, representing its MIME type, and a number, for mnemonic
- * access.
- *
- * This widget implements the #GtkRecentChooser interface.
- *
- * This widget creates its own #GtkRecentManager object. See the
- * gtk_recent_chooser_menu_new_for_manager() function to know how to create
- * a #GtkRecentChooserMenu widget bound to another #GtkRecentManager object.
- *
- * Returns: a new #GtkRecentChooserMenu
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_menu_new (void)
-{
- return g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
- "recent-manager", NULL,
- NULL);
-}
-
-/**
- * gtk_recent_chooser_menu_new_for_manager:
- * @manager: a #GtkRecentManager
- *
- * Creates a new #GtkRecentChooserMenu widget using @manager as
- * the underlying recently used resources manager.
- *
- * This is useful if you have implemented your own recent manager,
- * or if you have a customized instance of a #GtkRecentManager
- * object or if you wish to share a common #GtkRecentManager object
- * among multiple #GtkRecentChooser widgets.
- *
- * Returns: a new #GtkRecentChooserMenu, bound to @manager.
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_menu_new_for_manager (GtkRecentManager *manager)
-{
- g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
-
- return g_object_new (GTK_TYPE_RECENT_CHOOSER_MENU,
- "recent-manager", manager,
- NULL);
-}
-
-/**
- * gtk_recent_chooser_menu_get_show_numbers:
- * @menu: a #GtkRecentChooserMenu
- *
- * Returns the value set by gtk_recent_chooser_menu_set_show_numbers().
- *
- * Returns: %TRUE if numbers should be shown.
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_chooser_menu_get_show_numbers (GtkRecentChooserMenu *menu)
-{
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER_MENU (menu), FALSE);
-
- return menu->priv->show_numbers;
-}
-
-/**
- * gtk_recent_chooser_menu_set_show_numbers:
- * @menu: a #GtkRecentChooserMenu
- * @show_numbers: whether to show numbers
- *
- * Sets whether a number should be added to the items of @menu. The
- * numbers are shown to provide a unique character for a mnemonic to
- * be used inside ten menu item’s label. Only the first the items
- * get a number to avoid clashes.
- *
- * Since: 2.10
- */
-void
-gtk_recent_chooser_menu_set_show_numbers (GtkRecentChooserMenu *menu,
- gboolean show_numbers)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER_MENU (menu));
-
- if (menu->priv->show_numbers == show_numbers)
- return;
-
- menu->priv->show_numbers = show_numbers;
- g_object_notify (G_OBJECT (menu), "show-numbers");
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchoosermenu.h - Recently used items menu widget
- * Copyright (C) 2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_MENU_H__
-#define __GTK_RECENT_CHOOSER_MENU_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkmenu.h>
-#include <gtk/gtkrecentchooser.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RECENT_CHOOSER_MENU (gtk_recent_chooser_menu_get_type ())
-#define GTK_RECENT_CHOOSER_MENU(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenu))
-#define GTK_IS_RECENT_CHOOSER_MENU(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_MENU))
-#define GTK_RECENT_CHOOSER_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenuClass))
-#define GTK_IS_RECENT_CHOOSER_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_MENU))
-#define GTK_RECENT_CHOOSER_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_MENU, GtkRecentChooserMenuClass))
-
-typedef struct _GtkRecentChooserMenu GtkRecentChooserMenu;
-typedef struct _GtkRecentChooserMenuClass GtkRecentChooserMenuClass;
-typedef struct _GtkRecentChooserMenuPrivate GtkRecentChooserMenuPrivate;
-
-struct _GtkRecentChooserMenu
-{
- GtkMenu parent_instance;
-
- /*< private >*/
- GtkRecentChooserMenuPrivate *priv;
-};
-
-struct _GtkRecentChooserMenuClass
-{
- GtkMenuClass parent_class;
-
- /* padding for future expansion */
- void (* gtk_recent1) (void);
- void (* gtk_recent2) (void);
- void (* gtk_recent3) (void);
- void (* gtk_recent4) (void);
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_chooser_menu_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_menu_new (void);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_menu_new_for_manager (GtkRecentManager *manager);
-
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_chooser_menu_get_show_numbers (GtkRecentChooserMenu *menu);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_chooser_menu_set_show_numbers (GtkRecentChooserMenu *menu,
- gboolean show_numbers);
-
-G_END_DECLS
-
-#endif /* ! __GTK_RECENT_CHOOSER_MENU_H__ */
+++ /dev/null
-/* gtkrecentprivatechooser.h - Interface definitions for recent selectors UI
- *
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * All rights reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_PRIVATE_H__
-#define __GTK_RECENT_CHOOSER_PRIVATE_H__
-
-#include "gtkrecentmanager.h"
-#include "gtkrecentchooser.h"
-
-G_BEGIN_DECLS
-
-GtkRecentManager *_gtk_recent_chooser_get_recent_manager (GtkRecentChooser *chooser);
-GList * _gtk_recent_chooser_get_items (GtkRecentChooser *chooser,
- GtkRecentFilter *filter,
- GtkRecentSortFunc func,
- gpointer data);
-
-void _gtk_recent_chooser_item_activated (GtkRecentChooser *chooser);
-void _gtk_recent_chooser_selection_changed (GtkRecentChooser *chooser);
-
-G_END_DECLS
-
-#endif /* ! __GTK_RECENT_CHOOSER_PRIVATE_H__ */
+++ /dev/null
-/* gtkrecentchooserutils.h - Private utility functions for implementing a
- * GtkRecentChooser interface
- *
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * All rights reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Based on gtkfilechooserutils.c:
- * Copyright (C) 2003 Red Hat, Inc.
- */
-
-#include "config.h"
-
-#include "gtkrecentchooserutils.h"
-
-/* Methods */
-static void delegate_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy);
-static void delegate_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static void delegate_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter);
-static GSList *delegate_list_filters (GtkRecentChooser *chooser);
-static gboolean delegate_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static void delegate_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri);
-static GList *delegate_get_items (GtkRecentChooser *chooser);
-static GtkRecentManager *delegate_get_recent_manager (GtkRecentChooser *chooser);
-static void delegate_select_all (GtkRecentChooser *chooser);
-static void delegate_unselect_all (GtkRecentChooser *chooser);
-static gboolean delegate_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error);
-static gchar * delegate_get_current_uri (GtkRecentChooser *chooser);
-
-/* Signals */
-static void delegate_notify (GObject *object,
- GParamSpec *pspec,
- gpointer user_data);
-static void delegate_selection_changed (GtkRecentChooser *receiver,
- gpointer user_data);
-static void delegate_item_activated (GtkRecentChooser *receiver,
- gpointer user_data);
-
-/**
- * _gtk_recent_chooser_install_properties:
- * @klass: the class structure for a type deriving from #GObject
- *
- * Installs the necessary properties for a class implementing
- * #GtkRecentChooser. A #GtkParamSpecOverride property is installed
- * for each property, using the values from the #GtkRecentChooserProp
- * enumeration. The caller must make sure itself that the enumeration
- * values don’t collide with some other property values they
- * are using.
- */
-void
-_gtk_recent_chooser_install_properties (GObjectClass *klass)
-{
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER,
- "recent-manager");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE,
- "show-private");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SHOW_TIPS,
- "show-tips");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SHOW_ICONS,
- "show-icons");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND,
- "show-not-found");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE,
- "select-multiple");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_LIMIT,
- "limit");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY,
- "local-only");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_SORT_TYPE,
- "sort-type");
- g_object_class_override_property (klass,
- GTK_RECENT_CHOOSER_PROP_FILTER,
- "filter");
-}
-
-/**
- * _gtk_recent_chooser_delegate_iface_init:
- * @iface: a #GtkRecentChooserIface
- *
- * An interface-initialization function for use in cases where
- * an object is simply delegating the methods, signals of
- * the #GtkRecentChooser interface to another object.
- * _gtk_recent_chooser_set_delegate() must be called on each
- * instance of the object so that the delegate object can
- * be found.
- */
-void
-_gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface)
-{
- iface->set_current_uri = delegate_set_current_uri;
- iface->get_current_uri = delegate_get_current_uri;
- iface->select_uri = delegate_select_uri;
- iface->unselect_uri = delegate_unselect_uri;
- iface->select_all = delegate_select_all;
- iface->unselect_all = delegate_unselect_all;
- iface->get_items = delegate_get_items;
- iface->get_recent_manager = delegate_get_recent_manager;
- iface->set_sort_func = delegate_set_sort_func;
- iface->add_filter = delegate_add_filter;
- iface->remove_filter = delegate_remove_filter;
- iface->list_filters = delegate_list_filters;
-}
-
-/**
- * _gtk_recent_chooser_set_delegate:
- * @receiver: a #GObject implementing #GtkRecentChooser
- * @delegate: another #GObject implementing #GtkRecentChooser
- *
- * Establishes that calls on @receiver for #GtkRecentChooser
- * methods should be delegated to @delegate, and that
- * #GtkRecentChooser signals emitted on @delegate should be
- * forwarded to @receiver. Must be used in conjunction with
- * _gtk_recent_chooser_delegate_iface_init().
- */
-void
-_gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
- GtkRecentChooser *delegate)
-{
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (receiver));
- g_return_if_fail (GTK_IS_RECENT_CHOOSER (delegate));
-
- g_object_set_data (G_OBJECT (receiver),
- "gtk-recent-chooser-delegate", delegate);
-
- g_signal_connect (delegate, "notify",
- G_CALLBACK (delegate_notify), receiver);
- g_signal_connect (delegate, "selection-changed",
- G_CALLBACK (delegate_selection_changed), receiver);
- g_signal_connect (delegate, "item-activated",
- G_CALLBACK (delegate_item_activated), receiver);
-}
-
-GQuark
-_gtk_recent_chooser_delegate_get_quark (void)
-{
- static GQuark quark = 0;
-
- if (G_UNLIKELY (quark == 0))
- quark = g_quark_from_static_string ("gtk-recent-chooser-delegate");
-
- return quark;
-}
-
-static GtkRecentChooser *
-get_delegate (GtkRecentChooser *receiver)
-{
- return g_object_get_qdata (G_OBJECT (receiver),
- GTK_RECENT_CHOOSER_DELEGATE_QUARK);
-}
-
-static void
-delegate_set_sort_func (GtkRecentChooser *chooser,
- GtkRecentSortFunc sort_func,
- gpointer sort_data,
- GDestroyNotify data_destroy)
-{
- gtk_recent_chooser_set_sort_func (get_delegate (chooser),
- sort_func,
- sort_data,
- data_destroy);
-}
-
-static void
-delegate_add_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- gtk_recent_chooser_add_filter (get_delegate (chooser), filter);
-}
-
-static void
-delegate_remove_filter (GtkRecentChooser *chooser,
- GtkRecentFilter *filter)
-{
- gtk_recent_chooser_remove_filter (get_delegate (chooser), filter);
-}
-
-static GSList *
-delegate_list_filters (GtkRecentChooser *chooser)
-{
- return gtk_recent_chooser_list_filters (get_delegate (chooser));
-}
-
-static gboolean
-delegate_select_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- return gtk_recent_chooser_select_uri (get_delegate (chooser), uri, error);
-}
-
-static void
-delegate_unselect_uri (GtkRecentChooser *chooser,
- const gchar *uri)
-{
- gtk_recent_chooser_unselect_uri (get_delegate (chooser), uri);
-}
-
-static GList *
-delegate_get_items (GtkRecentChooser *chooser)
-{
- return gtk_recent_chooser_get_items (get_delegate (chooser));
-}
-
-static GtkRecentManager *
-delegate_get_recent_manager (GtkRecentChooser *chooser)
-{
- return _gtk_recent_chooser_get_recent_manager (get_delegate (chooser));
-}
-
-static void
-delegate_select_all (GtkRecentChooser *chooser)
-{
- gtk_recent_chooser_select_all (get_delegate (chooser));
-}
-
-static void
-delegate_unselect_all (GtkRecentChooser *chooser)
-{
- gtk_recent_chooser_unselect_all (get_delegate (chooser));
-}
-
-static gboolean
-delegate_set_current_uri (GtkRecentChooser *chooser,
- const gchar *uri,
- GError **error)
-{
- return gtk_recent_chooser_set_current_uri (get_delegate (chooser), uri, error);
-}
-
-static gchar *
-delegate_get_current_uri (GtkRecentChooser *chooser)
-{
- return gtk_recent_chooser_get_current_uri (get_delegate (chooser));
-}
-
-static void
-delegate_notify (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- gpointer iface;
-
- iface = g_type_interface_peek (g_type_class_peek (G_OBJECT_TYPE (object)),
- gtk_recent_chooser_get_type ());
- if (g_object_interface_find_property (iface, pspec->name))
- g_object_notify (user_data, pspec->name);
-}
-
-static void
-delegate_selection_changed (GtkRecentChooser *receiver,
- gpointer user_data)
-{
- _gtk_recent_chooser_selection_changed (GTK_RECENT_CHOOSER (user_data));
-}
-
-static void
-delegate_item_activated (GtkRecentChooser *receiver,
- gpointer user_data)
-{
- _gtk_recent_chooser_item_activated (GTK_RECENT_CHOOSER (user_data));
-}
-
-static gint
-sort_recent_items_mru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a);
-}
-
-static gint
-sort_recent_items_lru (GtkRecentInfo *a,
- GtkRecentInfo *b,
- gpointer unused)
-{
- g_assert (a != NULL && b != NULL);
-
- return -1 * (gtk_recent_info_get_modified (b) - gtk_recent_info_get_modified (a));
-}
-
-typedef struct
-{
- GtkRecentSortFunc func;
- gpointer data;
-} SortRecentData;
-
-/* our proxy sorting function */
-static gint
-sort_recent_items_proxy (gpointer *a,
- gpointer *b,
- gpointer user_data)
-{
- GtkRecentInfo *info_a = (GtkRecentInfo *) a;
- GtkRecentInfo *info_b = (GtkRecentInfo *) b;
- SortRecentData *sort_recent = user_data;
-
- if (sort_recent->func)
- return (* sort_recent->func) (info_a, info_b, sort_recent->data);
-
- /* fallback */
- return 0;
-}
-
-static gboolean
-get_is_recent_filtered (GtkRecentFilter *filter,
- GtkRecentInfo *info)
-{
- GtkRecentFilterInfo filter_info;
- GtkRecentFilterFlags needed;
- gboolean retval;
-
- g_assert (info != NULL);
-
- needed = gtk_recent_filter_get_needed (filter);
-
- filter_info.contains = GTK_RECENT_FILTER_URI | GTK_RECENT_FILTER_MIME_TYPE;
-
- filter_info.uri = gtk_recent_info_get_uri (info);
- filter_info.mime_type = gtk_recent_info_get_mime_type (info);
-
- if (needed & GTK_RECENT_FILTER_DISPLAY_NAME)
- {
- filter_info.display_name = gtk_recent_info_get_display_name (info);
- filter_info.contains |= GTK_RECENT_FILTER_DISPLAY_NAME;
- }
- else
- filter_info.uri = NULL;
-
- if (needed & GTK_RECENT_FILTER_APPLICATION)
- {
- filter_info.applications = (const gchar **) gtk_recent_info_get_applications (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_APPLICATION;
- }
- else
- filter_info.applications = NULL;
-
- if (needed & GTK_RECENT_FILTER_GROUP)
- {
- filter_info.groups = (const gchar **) gtk_recent_info_get_groups (info, NULL);
- filter_info.contains |= GTK_RECENT_FILTER_GROUP;
- }
- else
- filter_info.groups = NULL;
-
- if (needed & GTK_RECENT_FILTER_AGE)
- {
- filter_info.age = gtk_recent_info_get_age (info);
- filter_info.contains |= GTK_RECENT_FILTER_AGE;
- }
- else
- filter_info.age = -1;
-
- retval = gtk_recent_filter_filter (filter, &filter_info);
-
- /* these we own */
- if (filter_info.applications)
- g_strfreev ((gchar **) filter_info.applications);
- if (filter_info.groups)
- g_strfreev ((gchar **) filter_info.groups);
-
- return !retval;
-}
-
-/*
- * _gtk_recent_chooser_get_items:
- * @chooser: a #GtkRecentChooser
- * @filter: a #GtkRecentFilter
- * @sort_func: (allow-none): sorting function, or %NULL
- * @sort_data: (allow-none): sorting function data, or %NULL
- *
- * Default implementation for getting the filtered, sorted and
- * clamped list of recently used resources from a #GtkRecentChooser.
- * This function should be used by implementations of the
- * #GtkRecentChooser interface inside the GtkRecentChooser::get_items
- * vfunc.
- *
- * Returns: a list of #GtkRecentInfo objects
- */
-GList *
-_gtk_recent_chooser_get_items (GtkRecentChooser *chooser,
- GtkRecentFilter *filter,
- GtkRecentSortFunc sort_func,
- gpointer sort_data)
-{
- GtkRecentManager *manager;
- gint limit;
- GtkRecentSortType sort_type;
- GList *items;
- GCompareDataFunc compare_func;
- gint length;
-
- g_return_val_if_fail (GTK_IS_RECENT_CHOOSER (chooser), NULL);
-
- manager = _gtk_recent_chooser_get_recent_manager (chooser);
- if (!manager)
- return NULL;
-
- items = gtk_recent_manager_get_items (manager);
- if (!items)
- return NULL;
-
- limit = gtk_recent_chooser_get_limit (chooser);
- if (limit == 0)
- return NULL;
-
- if (filter)
- {
- GList *filter_items, *l;
- gboolean local_only = FALSE;
- gboolean show_private = FALSE;
- gboolean show_not_found = FALSE;
-
- g_object_get (G_OBJECT (chooser),
- "local-only", &local_only,
- "show-private", &show_private,
- "show-not-found", &show_not_found,
- NULL);
-
- filter_items = NULL;
- for (l = items; l != NULL; l = l->next)
- {
- GtkRecentInfo *info = l->data;
- gboolean remove_item = FALSE;
-
- if (get_is_recent_filtered (filter, info))
- remove_item = TRUE;
-
- if (local_only && !gtk_recent_info_is_local (info))
- remove_item = TRUE;
-
- if (!show_private && gtk_recent_info_get_private_hint (info))
- remove_item = TRUE;
-
- if (!show_not_found && !gtk_recent_info_exists (info))
- remove_item = TRUE;
-
- if (!remove_item)
- filter_items = g_list_prepend (filter_items, info);
- else
- gtk_recent_info_unref (info);
- }
-
- g_list_free (items);
- items = filter_items;
- }
-
- if (!items)
- return NULL;
-
- sort_type = gtk_recent_chooser_get_sort_type (chooser);
- switch (sort_type)
- {
- case GTK_RECENT_SORT_NONE:
- compare_func = NULL;
- break;
- case GTK_RECENT_SORT_MRU:
- compare_func = (GCompareDataFunc) sort_recent_items_mru;
- break;
- case GTK_RECENT_SORT_LRU:
- compare_func = (GCompareDataFunc) sort_recent_items_lru;
- break;
- case GTK_RECENT_SORT_CUSTOM:
- compare_func = (GCompareDataFunc) sort_recent_items_proxy;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- if (compare_func)
- {
- SortRecentData sort_recent;
-
- sort_recent.func = sort_func;
- sort_recent.data = sort_data;
-
- items = g_list_sort_with_data (items, compare_func, &sort_recent);
- }
-
- length = g_list_length (items);
- if ((limit != -1) && (length > limit))
- {
- GList *clamp, *l;
-
- clamp = g_list_nth (items, limit - 1);
- if (!clamp)
- return items;
-
- l = clamp->next;
- clamp->next = NULL;
-
- g_list_free_full (l, (GDestroyNotify) gtk_recent_info_unref);
- }
-
- return items;
-}
+++ /dev/null
-/* gtkrecentchooserutils.h - Private utility functions for implementing a
- * GtkRecentChooser interface
- *
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * All rights reserved
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- *
- * Based on gtkfilechooserutils.h:
- * Copyright (C) 2003 Red Hat, Inc.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_UTILS_H__
-#define __GTK_RECENT_CHOOSER_UTILS_H__
-
-#include "gtkrecentchooserprivate.h"
-
-G_BEGIN_DECLS
-
-
-#define GTK_RECENT_CHOOSER_DELEGATE_QUARK (_gtk_recent_chooser_delegate_get_quark ())
-
-typedef enum {
- GTK_RECENT_CHOOSER_PROP_FIRST = 0x3000,
- GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER,
- GTK_RECENT_CHOOSER_PROP_SHOW_PRIVATE,
- GTK_RECENT_CHOOSER_PROP_SHOW_NOT_FOUND,
- GTK_RECENT_CHOOSER_PROP_SHOW_TIPS,
- GTK_RECENT_CHOOSER_PROP_SHOW_ICONS,
- GTK_RECENT_CHOOSER_PROP_SELECT_MULTIPLE,
- GTK_RECENT_CHOOSER_PROP_LIMIT,
- GTK_RECENT_CHOOSER_PROP_LOCAL_ONLY,
- GTK_RECENT_CHOOSER_PROP_SORT_TYPE,
- GTK_RECENT_CHOOSER_PROP_FILTER,
- GTK_RECENT_CHOOSER_PROP_LAST
-} GtkRecentChooserProp;
-
-void _gtk_recent_chooser_install_properties (GObjectClass *klass);
-
-void _gtk_recent_chooser_delegate_iface_init (GtkRecentChooserIface *iface);
-void _gtk_recent_chooser_set_delegate (GtkRecentChooser *receiver,
- GtkRecentChooser *delegate);
-
-GQuark _gtk_recent_chooser_delegate_get_quark (void) G_GNUC_CONST;
-
-G_END_DECLS
-
-#endif /* __GTK_RECENT_CHOOSER_UTILS_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserwidget.c: embeddable recently used resources chooser widget
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include "gtkrecentchooserwidget.h"
-#include "gtkrecentchooserdefault.h"
-#include "gtkrecentchooserutils.h"
-#include "gtkorientable.h"
-#include "gtktypebuiltins.h"
-
-/**
- * SECTION:gtkrecentchooserwidget
- * @Short_description: Displays recently used files
- * @Title: GtkRecentChooserWidget
- * @See_also:#GtkRecentChooser, #GtkRecentChooserDialog
- *
- * #GtkRecentChooserWidget is a widget suitable for selecting recently used
- * files. It is the main building block of a #GtkRecentChooserDialog. Most
- * applications will only need to use the latter; you can use
- * #GtkRecentChooserWidget as part of a larger window if you have special needs.
- *
- * Note that #GtkRecentChooserWidget does not have any methods of its own.
- * Instead, you should use the functions that work on a #GtkRecentChooser.
- *
- * Recently used files are supported since GTK+ 2.10.
- */
-
-
-struct _GtkRecentChooserWidgetPrivate
-{
- GtkRecentManager *manager;
-
- GtkWidget *chooser;
-};
-
-static void gtk_recent_chooser_widget_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void gtk_recent_chooser_widget_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void gtk_recent_chooser_widget_finalize (GObject *object);
-
-
-G_DEFINE_TYPE_WITH_CODE (GtkRecentChooserWidget,
- gtk_recent_chooser_widget,
- GTK_TYPE_WIDGET,
- G_ADD_PRIVATE (GtkRecentChooserWidget)
- G_IMPLEMENT_INTERFACE (GTK_TYPE_RECENT_CHOOSER,
- _gtk_recent_chooser_delegate_iface_init))
-
-static void
-gtk_recent_chooser_widget_constructed (GObject *gobject)
-{
- GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (gobject);
-
- self->priv->chooser = _gtk_recent_chooser_default_new (self->priv->manager);
-
- gtk_widget_set_parent (self->priv->chooser, GTK_WIDGET (self));
-
- _gtk_recent_chooser_set_delegate (GTK_RECENT_CHOOSER (self),
- GTK_RECENT_CHOOSER (self->priv->chooser));
-}
-
-static void
-gtk_recent_chooser_widget_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserWidgetPrivate *priv;
-
- priv = gtk_recent_chooser_widget_get_instance_private (GTK_RECENT_CHOOSER_WIDGET (object));
-
- switch (prop_id)
- {
- case GTK_RECENT_CHOOSER_PROP_RECENT_MANAGER:
- priv->manager = g_value_get_object (value);
- break;
- default:
- g_object_set_property (G_OBJECT (priv->chooser), pspec->name, value);
- break;
- }
-}
-
-static void
-gtk_recent_chooser_widget_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GtkRecentChooserWidgetPrivate *priv;
-
- priv = gtk_recent_chooser_widget_get_instance_private (GTK_RECENT_CHOOSER_WIDGET (object));
-
- g_object_get_property (G_OBJECT (priv->chooser), pspec->name, value);
-}
-
-static void
-gtk_recent_chooser_widget_finalize (GObject *object)
-{
- GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (object);
-
- self->priv->manager = NULL;
-
- gtk_widget_unparent (self->priv->chooser);
-
- G_OBJECT_CLASS (gtk_recent_chooser_widget_parent_class)->finalize (object);
-}
-
-static void
-gtk_recent_chooser_widget_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline)
-{
- GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
- GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
-
- gtk_widget_measure (priv->chooser, orientation, for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
-}
-
-static void
-gtk_recent_chooser_widget_snapshot (GtkWidget *widget,
- GtkSnapshot *snapshot)
-{
- GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
- GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
-
- gtk_widget_snapshot_child (widget, priv->chooser, snapshot);
-}
-
-static void
-gtk_recent_chooser_widget_size_allocate (GtkWidget *widget,
- const GtkAllocation *allocation,
- int baseline,
- GtkAllocation *out_clip)
-{
- GtkRecentChooserWidget *self = GTK_RECENT_CHOOSER_WIDGET (widget);
- GtkRecentChooserWidgetPrivate *priv = gtk_recent_chooser_widget_get_instance_private (self);
-
- GTK_WIDGET_CLASS (gtk_recent_chooser_widget_parent_class)->size_allocate (widget, allocation, -1, out_clip);
-
- gtk_widget_size_allocate (priv->chooser, allocation, -1, out_clip);
-}
-
-static void
-gtk_recent_chooser_widget_class_init (GtkRecentChooserWidgetClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-
- gobject_class->constructed = gtk_recent_chooser_widget_constructed;
- gobject_class->set_property = gtk_recent_chooser_widget_set_property;
- gobject_class->get_property = gtk_recent_chooser_widget_get_property;
- gobject_class->finalize = gtk_recent_chooser_widget_finalize;
-
- widget_class->measure = gtk_recent_chooser_widget_measure;
- widget_class->size_allocate = gtk_recent_chooser_widget_size_allocate;
- widget_class->snapshot = gtk_recent_chooser_widget_snapshot;
-
- _gtk_recent_chooser_install_properties (gobject_class);
-}
-
-static void
-gtk_recent_chooser_widget_init (GtkRecentChooserWidget *widget)
-{
- widget->priv = gtk_recent_chooser_widget_get_instance_private (widget);
-
- gtk_widget_set_has_window (GTK_WIDGET (widget), FALSE);
-}
-
-/*
- * Public API
- */
-
-/**
- * gtk_recent_chooser_widget_new:
- *
- * Creates a new #GtkRecentChooserWidget object. This is an embeddable widget
- * used to access the recently used resources list.
- *
- * Returns: a new #GtkRecentChooserWidget
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_widget_new (void)
-{
- return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET, NULL);
-}
-
-/**
- * gtk_recent_chooser_widget_new_for_manager:
- * @manager: a #GtkRecentManager
- *
- * Creates a new #GtkRecentChooserWidget with a specified recent manager.
- *
- * This is useful if you have implemented your own recent manager, or if you
- * have a customized instance of a #GtkRecentManager object.
- *
- * Returns: a new #GtkRecentChooserWidget
- *
- * Since: 2.10
- */
-GtkWidget *
-gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager)
-{
- g_return_val_if_fail (manager == NULL || GTK_IS_RECENT_MANAGER (manager), NULL);
-
- return g_object_new (GTK_TYPE_RECENT_CHOOSER_WIDGET,
- "recent-manager", manager,
- NULL);
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentchooserwidget.h: embeddable recently used resources chooser widget
- * Copyright (C) 2006 Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_CHOOSER_WIDGET_H__
-#define __GTK_RECENT_CHOOSER_WIDGET_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <gtk/gtkrecentchooser.h>
-#include <gtk/gtkwidget.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RECENT_CHOOSER_WIDGET (gtk_recent_chooser_widget_get_type ())
-#define GTK_RECENT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidget))
-#define GTK_IS_RECENT_CHOOSER_WIDGET(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET))
-#define GTK_RECENT_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidgetClass))
-#define GTK_IS_RECENT_CHOOSER_WIDGET_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_RECENT_CHOOSER_WIDGET))
-#define GTK_RECENT_CHOOSER_WIDGET_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_RECENT_CHOOSER_WIDGET, GtkRecentChooserWidgetClass))
-
-typedef struct _GtkRecentChooserWidget GtkRecentChooserWidget;
-typedef struct _GtkRecentChooserWidgetClass GtkRecentChooserWidgetClass;
-
-typedef struct _GtkRecentChooserWidgetPrivate GtkRecentChooserWidgetPrivate;
-
-struct _GtkRecentChooserWidget
-{
- GtkWidget parent_instance;
-
- /*< private >*/
- GtkRecentChooserWidgetPrivate *priv;
-};
-
-struct _GtkRecentChooserWidgetClass
-{
- GtkWidgetClass parent_class;
-
- /* Padding for future expansion */
- void (*_gtk_reserved1) (void);
- void (*_gtk_reserved2) (void);
- void (*_gtk_reserved3) (void);
- void (*_gtk_reserved4) (void);
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_chooser_widget_get_type (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_widget_new (void);
-GDK_AVAILABLE_IN_ALL
-GtkWidget *gtk_recent_chooser_widget_new_for_manager (GtkRecentManager *manager);
-
-G_END_DECLS
-
-#endif /* __GTK_RECENT_CHOOSER_WIDGET_H__ */
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentfilter.h - Filter object for recently used resources
- * Copyright (C) 2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-/**
- * SECTION:gtkrecentfilter
- * @Short_Description: A filter for selecting a subset of recently used files
- * @Title: GtkRecentFilter
- *
- * A #GtkRecentFilter can be used to restrict the files being shown
- * in a #GtkRecentChooser. Files can be filtered based on their name
- * (with gtk_recent_filter_add_pattern()), on their mime type (with
- * gtk_file_filter_add_mime_type()), on the application that has
- * registered them (with gtk_recent_filter_add_application()), or by
- * a custom filter function (with gtk_recent_filter_add_custom()).
- *
- * Filtering by mime type handles aliasing and subclassing of mime
- * types; e.g. a filter for text/plain also matches a file with mime
- * type application/rtf, since application/rtf is a subclass of text/plain.
- * Note that #GtkRecentFilter allows wildcards for the subtype of a
- * mime type, so you can e.g. filter for image/\*.
- *
- * Normally, filters are used by adding them to a #GtkRecentChooser,
- * see gtk_recent_chooser_add_filter(), but it is also possible to
- * manually use a filter on a file with gtk_recent_filter_filter().
- *
- * Recently used files are supported since GTK+ 2.10.
- *
- * ## GtkRecentFilter as GtkBuildable
- *
- * The GtkRecentFilter implementation of the GtkBuildable interface
- * supports adding rules using the <mime-types>, <patterns> and
- * <applications> elements and listing the rules within. Specifying
- * a <mime-type>, <pattern> or <application> has the same effect as
- * calling gtk_recent_filter_add_mime_type(),
- * gtk_recent_filter_add_pattern() or gtk_recent_filter_add_application().
- *
- * An example of a UI definition fragment specifying GtkRecentFilter rules:
- * |[
- * <object class="GtkRecentFilter">
- * <mime-types>
- * <mime-type>text/plain</mime-type>
- * <mime-type>image/png</mime-type>
- * </mime-types>
- * <patterns>
- * <pattern>*.txt</pattern>
- * <pattern>*.png</pattern>
- * </patterns>
- * <applications>
- * <application>gimp</application>
- * <application>gedit</application>
- * <application>glade</application>
- * </applications>
- * </object>
- * ]|
- */
-
-#include "config.h"
-#include <string.h>
-
-#include <gdk-pixbuf/gdk-pixbuf.h>
-
-#include "gtkrecentfilter.h"
-#include "gtkbuildable.h"
-#include "gtkbuilderprivate.h"
-#include "gtkintl.h"
-#include "gtkprivate.h"
-
-static void gtk_recent_filter_buildable_init (GtkBuildableIface *iface);
-static gboolean gtk_recent_filter_buildable_custom_tag_start (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- GMarkupParser *parser,
- gpointer *data);
-static void gtk_recent_filter_buildable_custom_tag_end (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- gpointer *data);
-
-typedef struct _GtkRecentFilterClass GtkRecentFilterClass;
-typedef struct _FilterRule FilterRule;
-
-typedef enum {
- FILTER_RULE_URI,
- FILTER_RULE_DISPLAY_NAME,
- FILTER_RULE_MIME_TYPE,
- FILTER_RULE_PIXBUF_FORMATS,
- FILTER_RULE_APPLICATION,
- FILTER_RULE_AGE,
- FILTER_RULE_GROUP,
- FILTER_RULE_CUSTOM
-} FilterRuleType;
-
-struct _GtkRecentFilter
-{
- GInitiallyUnowned parent_instance;
-
- gchar *name;
- GSList *rules;
-
- GtkRecentFilterFlags needed;
-};
-
-struct _GtkRecentFilterClass
-{
- GInitiallyUnownedClass parent_class;
-};
-
-struct _FilterRule
-{
- FilterRuleType type;
- GtkRecentFilterFlags needed;
-
- union {
- gchar *uri;
- gchar *pattern;
- gchar *mime_type;
- GSList *pixbuf_formats;
- gchar *application;
- gchar *group;
- gint age;
- struct {
- GtkRecentFilterFunc func;
- gpointer data;
- GDestroyNotify data_destroy;
- } custom;
- } u;
-};
-
-G_DEFINE_TYPE_WITH_CODE (GtkRecentFilter, gtk_recent_filter, G_TYPE_INITIALLY_UNOWNED,
- G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
- gtk_recent_filter_buildable_init))
-
-
-static void
-filter_rule_free (FilterRule *rule)
-{
- switch (rule->type)
- {
- case FILTER_RULE_MIME_TYPE:
- g_free (rule->u.mime_type);
- break;
- case FILTER_RULE_URI:
- g_free (rule->u.uri);
- break;
- case FILTER_RULE_DISPLAY_NAME:
- g_free (rule->u.pattern);
- break;
- case FILTER_RULE_PIXBUF_FORMATS:
- g_slist_free (rule->u.pixbuf_formats);
- break;
- case FILTER_RULE_AGE:
- break;
- case FILTER_RULE_APPLICATION:
- g_free (rule->u.application);
- break;
- case FILTER_RULE_GROUP:
- g_free (rule->u.group);
- break;
- case FILTER_RULE_CUSTOM:
- if (rule->u.custom.data_destroy)
- rule->u.custom.data_destroy (rule->u.custom.data);
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- g_free (rule);
-}
-
-static void
-gtk_recent_filter_finalize (GObject *object)
-{
- GtkRecentFilter *filter = GTK_RECENT_FILTER (object);
-
- g_free (filter->name);
- g_slist_free_full (filter->rules, (GDestroyNotify) filter_rule_free);
-
- G_OBJECT_CLASS (gtk_recent_filter_parent_class)->finalize (object);
-}
-
-static void
-gtk_recent_filter_class_init (GtkRecentFilterClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->finalize = gtk_recent_filter_finalize;
-}
-
-static void
-gtk_recent_filter_init (GtkRecentFilter *filter)
-{
-
-}
-
-
-/*
- * GtkBuildable implementation
- */
-static void
-gtk_recent_filter_buildable_init (GtkBuildableIface *iface)
-{
- iface->custom_tag_start = gtk_recent_filter_buildable_custom_tag_start;
- iface->custom_tag_end = gtk_recent_filter_buildable_custom_tag_end;
-}
-
-
-typedef enum {
- PARSE_MIME_TYPES,
- PARSE_PATTERNS,
- PARSE_APPLICATIONS
-} ParserType;
-
-typedef struct {
- GtkRecentFilter *filter;
- GtkBuilder *builder;
- ParserType type;
- GString *string;
- gboolean parsing;
-} SubParserData;
-
-static void
-parser_start_element (GMarkupParseContext *context,
- const gchar *element_name,
- const gchar **names,
- const gchar **values,
- gpointer user_data,
- GError **error)
-{
- SubParserData *data = (SubParserData*)user_data;
-
- if (!g_markup_collect_attributes (element_name, names, values, error,
- G_MARKUP_COLLECT_INVALID, NULL, NULL,
- G_MARKUP_COLLECT_INVALID))
- {
- _gtk_builder_prefix_error (data->builder, context, error);
- return;
- }
-
- if (strcmp (element_name, "mime-types") == 0 ||
- strcmp (element_name, "patterns") == 0 ||
- strcmp (element_name, "applications") == 0)
- {
- if (!_gtk_builder_check_parent (data->builder, context, "object", error))
- return;
- }
- else if (strcmp (element_name, "mime-type") == 0)
- {
- if (!_gtk_builder_check_parent (data->builder, context, "mime-types", error))
- return;
-
- data->parsing = TRUE;
- }
- else if (strcmp (element_name, "pattern") == 0)
- {
- if (!_gtk_builder_check_parent (data->builder, context, "patterns", error))
- return;
-
- data->parsing = TRUE;
- }
- else if (strcmp (element_name, "application") == 0)
- {
- if (!_gtk_builder_check_parent (data->builder, context, "applications", error))
- return;
-
- data->parsing = TRUE;
- }
- else
- {
- _gtk_builder_error_unhandled_tag (data->builder, context,
- "GtkRecentFilter", element_name,
- error);
- }
-}
-
-static void
-parser_text_element (GMarkupParseContext *context,
- const gchar *text,
- gsize text_len,
- gpointer user_data,
- GError **error)
-{
- SubParserData *data = (SubParserData*)user_data;
-
- if (data->parsing)
- g_string_append_len (data->string, text, text_len);
-}
-
-static void
-parser_end_element (GMarkupParseContext *context,
- const gchar *element_name,
- gpointer user_data,
- GError **error)
-{
- SubParserData *data = (SubParserData*)user_data;
-
- if (data->string)
- {
- switch (data->type)
- {
- case PARSE_MIME_TYPES:
- gtk_recent_filter_add_mime_type (data->filter, data->string->str);
- break;
- case PARSE_PATTERNS:
- gtk_recent_filter_add_pattern (data->filter, data->string->str);
- break;
- case PARSE_APPLICATIONS:
- gtk_recent_filter_add_application (data->filter, data->string->str);
- break;
- default:
- break;
- }
- }
-
- g_string_set_size (data->string, 0);
- data->parsing = FALSE;
-}
-
-static const GMarkupParser sub_parser =
- {
- parser_start_element,
- parser_end_element,
- parser_text_element,
- };
-
-static gboolean
-gtk_recent_filter_buildable_custom_tag_start (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- GMarkupParser *parser,
- gpointer *parser_data)
-{
- SubParserData *data = NULL;
-
- if (strcmp (tagname, "mime-types") == 0)
- {
- data = g_slice_new0 (SubParserData);
- data->string = g_string_new ("");
- data->type = PARSE_MIME_TYPES;
- data->filter = GTK_RECENT_FILTER (buildable);
- data->builder = builder;
-
- *parser = sub_parser;
- *parser_data = data;
- }
- else if (strcmp (tagname, "patterns") == 0)
- {
- data = g_slice_new0 (SubParserData);
- data->string = g_string_new ("");
- data->type = PARSE_PATTERNS;
- data->filter = GTK_RECENT_FILTER (buildable);
- data->builder = builder;
-
- *parser = sub_parser;
- *parser_data = data;
- }
- else if (strcmp (tagname, "applications") == 0)
- {
- data = g_slice_new0 (SubParserData);
- data->string = g_string_new ("");
- data->type = PARSE_APPLICATIONS;
- data->filter = GTK_RECENT_FILTER (buildable);
- data->builder = builder;
-
- *parser = sub_parser;
- *parser_data = data;
- }
-
- return data != NULL;
-}
-
-static void
-gtk_recent_filter_buildable_custom_tag_end (GtkBuildable *buildable,
- GtkBuilder *builder,
- GObject *child,
- const gchar *tagname,
- gpointer *parser_data)
-{
- if (strcmp (tagname, "mime-types") == 0 ||
- strcmp (tagname, "patterns") == 0 ||
- strcmp (tagname, "applications") == 0)
- {
- SubParserData *data = (SubParserData*)parser_data;
-
- g_string_free (data->string, TRUE);
- g_slice_free (SubParserData, data);
- }
-}
-
-/*
- * Public API
- */
-
-/**
- * gtk_recent_filter_new:
- *
- * Creates a new #GtkRecentFilter with no rules added to it.
- * Such filter does not accept any recently used resources, so is not
- * particularly useful until you add rules with
- * gtk_recent_filter_add_pattern(), gtk_recent_filter_add_mime_type(),
- * gtk_recent_filter_add_application(), gtk_recent_filter_add_age().
- * To create a filter that accepts any recently used resource, use:
- * |[<!-- language="C" -->
- * GtkRecentFilter *filter = gtk_recent_filter_new ();
- * gtk_recent_filter_add_pattern (filter, "*");
- * ]|
- *
- * Returns: a new #GtkRecentFilter
- *
- * Since: 2.10
- */
-GtkRecentFilter *
-gtk_recent_filter_new (void)
-{
- return g_object_new (GTK_TYPE_RECENT_FILTER, NULL);
-}
-
-/**
- * gtk_recent_filter_set_name:
- * @filter: a #GtkRecentFilter
- * @name: then human readable name of @filter
- *
- * Sets the human-readable name of the filter; this is the string
- * that will be displayed in the recently used resources selector
- * user interface if there is a selectable list of filters.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_set_name (GtkRecentFilter *filter,
- const gchar *name)
-{
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
-
- g_free (filter->name);
-
- if (name)
- filter->name = g_strdup (name);
-}
-
-/**
- * gtk_recent_filter_get_name:
- * @filter: a #GtkRecentFilter
- *
- * Gets the human-readable name for the filter.
- * See gtk_recent_filter_set_name().
- *
- * Returns: (nullable): the name of the filter, or %NULL. The returned string
- * is owned by the filter object and should not be freed.
- *
- * Since: 2.10
- */
-const gchar *
-gtk_recent_filter_get_name (GtkRecentFilter *filter)
-{
- g_return_val_if_fail (GTK_IS_RECENT_FILTER (filter), NULL);
-
- return filter->name;
-}
-
-/**
- * gtk_recent_filter_get_needed:
- * @filter: a #GtkRecentFilter
- *
- * Gets the fields that need to be filled in for the #GtkRecentFilterInfo
- * passed to gtk_recent_filter_filter()
- *
- * This function will not typically be used by applications; it
- * is intended principally for use in the implementation of
- * #GtkRecentChooser.
- *
- * Returns: bitfield of flags indicating needed fields when
- * calling gtk_recent_filter_filter()
- *
- * Since: 2.10
- */
-GtkRecentFilterFlags
-gtk_recent_filter_get_needed (GtkRecentFilter *filter)
-{
- return filter->needed;
-}
-
-static void
-recent_filter_add_rule (GtkRecentFilter *filter,
- FilterRule *rule)
-{
- filter->needed |= rule->needed;
- filter->rules = g_slist_append (filter->rules, rule);
-}
-
-/**
- * gtk_recent_filter_add_mime_type:
- * @filter: a #GtkRecentFilter
- * @mime_type: a MIME type
- *
- * Adds a rule that allows resources based on their registered MIME type.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_mime_type (GtkRecentFilter *filter,
- const gchar *mime_type)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
- g_return_if_fail (mime_type != NULL);
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_MIME_TYPE;
- rule->needed = GTK_RECENT_FILTER_MIME_TYPE;
- rule->u.mime_type = g_strdup (mime_type);
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_pattern:
- * @filter: a #GtkRecentFilter
- * @pattern: a file pattern
- *
- * Adds a rule that allows resources based on a pattern matching their
- * display name.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_pattern (GtkRecentFilter *filter,
- const gchar *pattern)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
- g_return_if_fail (pattern != NULL);
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_DISPLAY_NAME;
- rule->needed = GTK_RECENT_FILTER_DISPLAY_NAME;
- rule->u.pattern = g_strdup (pattern);
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_pixbuf_formats:
- * @filter: a #GtkRecentFilter
- *
- * Adds a rule allowing image files in the formats supported
- * by GdkPixbuf.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_pixbuf_formats (GtkRecentFilter *filter)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_PIXBUF_FORMATS;
- rule->needed = GTK_RECENT_FILTER_MIME_TYPE;
- rule->u.pixbuf_formats = gdk_pixbuf_get_formats ();
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_application:
- * @filter: a #GtkRecentFilter
- * @application: an application name
- *
- * Adds a rule that allows resources based on the name of the application
- * that has registered them.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_application (GtkRecentFilter *filter,
- const gchar *application)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
- g_return_if_fail (application != NULL);
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_APPLICATION;
- rule->needed = GTK_RECENT_FILTER_APPLICATION;
- rule->u.application = g_strdup (application);
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_group:
- * @filter: a #GtkRecentFilter
- * @group: a group name
- *
- * Adds a rule that allows resources based on the name of the group
- * to which they belong
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_group (GtkRecentFilter *filter,
- const gchar *group)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
- g_return_if_fail (group != NULL);
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_GROUP;
- rule->needed = GTK_RECENT_FILTER_GROUP;
- rule->u.group = g_strdup (group);
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_age:
- * @filter: a #GtkRecentFilter
- * @days: number of days
- *
- * Adds a rule that allows resources based on their age - that is, the number
- * of days elapsed since they were last modified.
- *
- * Since: 2.10
- */
-void
-gtk_recent_filter_add_age (GtkRecentFilter *filter,
- gint days)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_AGE;
- rule->needed = GTK_RECENT_FILTER_AGE;
- rule->u.age = days;
-
- recent_filter_add_rule (filter, rule);
-}
-
-/**
- * gtk_recent_filter_add_custom:
- * @filter: a #GtkRecentFilter
- * @needed: bitfield of flags indicating the information that the custom
- * filter function needs.
- * @func: callback function; if the function returns %TRUE, then
- * the file will be displayed.
- * @data: data to pass to @func
- * @data_destroy: function to call to free @data when it is no longer needed.
- *
- * Adds a rule to a filter that allows resources based on a custom callback
- * function. The bitfield @needed which is passed in provides information
- * about what sorts of information that the filter function needs;
- * this allows GTK+ to avoid retrieving expensive information when
- * it isn’t needed by the filter.
- *
- * Since: 2.10
- **/
-void
-gtk_recent_filter_add_custom (GtkRecentFilter *filter,
- GtkRecentFilterFlags needed,
- GtkRecentFilterFunc func,
- gpointer data,
- GDestroyNotify data_destroy)
-{
- FilterRule *rule;
-
- g_return_if_fail (GTK_IS_RECENT_FILTER (filter));
- g_return_if_fail (func != NULL);
-
- rule = g_new0 (FilterRule, 1);
- rule->type = FILTER_RULE_CUSTOM;
- rule->needed = needed;
- rule->u.custom.func = func;
- rule->u.custom.data = data;
- rule->u.custom.data_destroy = data_destroy;
-
- recent_filter_add_rule (filter, rule);
-}
-
-
-/**
- * gtk_recent_filter_filter:
- * @filter: a #GtkRecentFilter
- * @filter_info: a #GtkRecentFilterInfo containing information
- * about a recently used resource
- *
- * Tests whether a file should be displayed according to @filter.
- * The #GtkRecentFilterInfo @filter_info should include
- * the fields returned from gtk_recent_filter_get_needed(), and
- * must set the #GtkRecentFilterInfo.contains field of @filter_info
- * to indicate which fields have been set.
- *
- * This function will not typically be used by applications; it
- * is intended principally for use in the implementation of
- * #GtkRecentChooser.
- *
- * Returns: %TRUE if the file should be displayed
- *
- * Since: 2.10
- */
-gboolean
-gtk_recent_filter_filter (GtkRecentFilter *filter,
- const GtkRecentFilterInfo *filter_info)
-{
- GSList *l;
-
- g_return_val_if_fail (GTK_IS_RECENT_FILTER (filter), FALSE);
- g_return_val_if_fail (filter_info != NULL, FALSE);
-
- for (l = filter->rules; l != NULL; l = l->next)
- {
- FilterRule *rule = (FilterRule *) l->data;
-
- if ((filter_info->contains & rule->needed) != rule->needed)
- continue;
-
- switch (rule->type)
- {
- case FILTER_RULE_MIME_TYPE:
- if (filter_info->mime_type != NULL)
- {
- gchar *filter_content_type, *rule_content_type;
- gboolean match;
-
- filter_content_type = g_content_type_from_mime_type (filter_info->mime_type);
- rule_content_type = g_content_type_from_mime_type (rule->u.mime_type);
- match = g_content_type_is_a (filter_content_type, rule_content_type);
- g_free (filter_content_type);
- g_free (rule_content_type);
-
- if (match)
- return TRUE;
- }
- break;
- case FILTER_RULE_APPLICATION:
- if (filter_info->applications)
- {
- gint i;
-
- for (i = 0; filter_info->applications[i] != NULL; i++)
- {
- if (strcmp (filter_info->applications[i], rule->u.application) == 0)
- return TRUE;
- }
- }
- break;
- case FILTER_RULE_GROUP:
- if (filter_info->groups)
- {
- gint i;
-
- for (i = 0; filter_info->groups[i] != NULL; i++)
- {
- if (strcmp (filter_info->groups[i], rule->u.group) == 0)
- return TRUE;
- }
- }
- break;
- case FILTER_RULE_PIXBUF_FORMATS:
- {
- GSList *list;
- if (!filter_info->mime_type)
- break;
-
- for (list = rule->u.pixbuf_formats; list; list = list->next)
- {
- gint i;
- gchar **mime_types;
-
- mime_types = gdk_pixbuf_format_get_mime_types (list->data);
-
- for (i = 0; mime_types[i] != NULL; i++)
- {
- if (strcmp (mime_types[i], filter_info->mime_type) == 0)
- {
- g_strfreev (mime_types);
- return TRUE;
- }
- }
-
- g_strfreev (mime_types);
- }
- break;
- }
- case FILTER_RULE_URI:
- if ((filter_info->uri != NULL) &&
- _gtk_fnmatch (rule->u.uri, filter_info->uri, FALSE))
- return TRUE;
- break;
- case FILTER_RULE_DISPLAY_NAME:
- if ((filter_info->display_name != NULL) &&
- _gtk_fnmatch (rule->u.pattern, filter_info->display_name, FALSE))
- return TRUE;
- break;
- case FILTER_RULE_AGE:
- if ((filter_info->age != -1) &&
- (filter_info->age < rule->u.age))
- return TRUE;
- break;
- case FILTER_RULE_CUSTOM:
- if (rule->u.custom.func (filter_info, rule->u.custom.data))
- return TRUE;
- break;
- default:
- g_assert_not_reached ();
- break;
- }
- }
-
- return FALSE;
-}
+++ /dev/null
-/* GTK - The GIMP Toolkit
- * gtkrecentfilter.h - Filter object for recently used resources
- * Copyright (C) 2006, Emmanuele Bassi
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GTK_RECENT_FILTER_H__
-#define __GTK_RECENT_FILTER_H__
-
-#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
-#error "Only <gtk/gtk.h> can be included directly."
-#endif
-
-#include <glib-object.h>
-#include <gdk/gdk.h>
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_RECENT_FILTER (gtk_recent_filter_get_type ())
-#define GTK_RECENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_RECENT_FILTER, GtkRecentFilter))
-#define GTK_IS_RECENT_FILTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_RECENT_FILTER))
-
-typedef struct _GtkRecentFilter GtkRecentFilter;
-typedef struct _GtkRecentFilterInfo GtkRecentFilterInfo;
-
-/**
- * GtkRecentFilterFlags:
- * @GTK_RECENT_FILTER_URI: the URI of the file being tested
- * @GTK_RECENT_FILTER_DISPLAY_NAME: the string that will be used to
- * display the file in the recent chooser
- * @GTK_RECENT_FILTER_MIME_TYPE: the mime type of the file
- * @GTK_RECENT_FILTER_APPLICATION: the list of applications that have
- * registered the file
- * @GTK_RECENT_FILTER_GROUP: the groups to which the file belongs to
- * @GTK_RECENT_FILTER_AGE: the number of days elapsed since the file
- * has been registered
- *
- * These flags indicate what parts of a #GtkRecentFilterInfo struct
- * are filled or need to be filled.
- */
-typedef enum {
- GTK_RECENT_FILTER_URI = 1 << 0,
- GTK_RECENT_FILTER_DISPLAY_NAME = 1 << 1,
- GTK_RECENT_FILTER_MIME_TYPE = 1 << 2,
- GTK_RECENT_FILTER_APPLICATION = 1 << 3,
- GTK_RECENT_FILTER_GROUP = 1 << 4,
- GTK_RECENT_FILTER_AGE = 1 << 5
-} GtkRecentFilterFlags;
-
-/**
- * GtkRecentFilterFunc:
- * @filter_info: a #GtkRecentFilterInfo that is filled according
- * to the @needed flags passed to gtk_recent_filter_add_custom()
- * @user_data: user data passed to gtk_recent_filter_add_custom()
- *
- * The type of function that is used with custom filters,
- * see gtk_recent_filter_add_custom().
- *
- * Returns: %TRUE if the file should be displayed
- */
-typedef gboolean (*GtkRecentFilterFunc) (const GtkRecentFilterInfo *filter_info,
- gpointer user_data);
-
-
-/**
- * GtkRecentFilterInfo:
- * @contains: #GtkRecentFilterFlags to indicate which fields are set.
- * @uri: (nullable): The URI of the file being tested.
- * @display_name: (nullable): The string that will be used to display
- * the file in the recent chooser.
- * @mime_type: (nullable): MIME type of the file.
- * @applications: (nullable) (array zero-terminated=1): The list of
- * applications that have registered the file.
- * @groups: (nullable) (array zero-terminated=1): The groups to which
- * the file belongs to.
- * @age: The number of days elapsed since the file has been
- * registered.
- *
- * A GtkRecentFilterInfo struct is used
- * to pass information about the tested file to gtk_recent_filter_filter().
- */
-struct _GtkRecentFilterInfo
-{
- GtkRecentFilterFlags contains;
-
- const gchar *uri;
- const gchar *display_name;
- const gchar *mime_type;
- const gchar **applications;
- const gchar **groups;
-
- gint age;
-};
-
-GDK_AVAILABLE_IN_ALL
-GType gtk_recent_filter_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_ALL
-GtkRecentFilter * gtk_recent_filter_new (void);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_set_name (GtkRecentFilter *filter,
- const gchar *name);
-GDK_AVAILABLE_IN_ALL
-const gchar * gtk_recent_filter_get_name (GtkRecentFilter *filter);
-
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_mime_type (GtkRecentFilter *filter,
- const gchar *mime_type);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_pattern (GtkRecentFilter *filter,
- const gchar *pattern);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_pixbuf_formats (GtkRecentFilter *filter);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_application (GtkRecentFilter *filter,
- const gchar *application);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_group (GtkRecentFilter *filter,
- const gchar *group);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_age (GtkRecentFilter *filter,
- gint days);
-GDK_AVAILABLE_IN_ALL
-void gtk_recent_filter_add_custom (GtkRecentFilter *filter,
- GtkRecentFilterFlags needed,
- GtkRecentFilterFunc func,
- gpointer data,
- GDestroyNotify data_destroy);
-
-GDK_AVAILABLE_IN_ALL
-GtkRecentFilterFlags gtk_recent_filter_get_needed (GtkRecentFilter *filter);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_recent_filter_filter (GtkRecentFilter *filter,
- const GtkRecentFilterInfo *filter_info);
-
-G_END_DECLS
-
-#endif /* ! __GTK_RECENT_FILTER_H__ */
'gtkprivate.c',
'gtkprogresstracker.c',
'gtkquery.c',
- 'gtkrecentchooserutils.c',
'gtksearchengine.c',
'gtksearchenginemodel.c',
'gtksearchenginesimple.c',
'gtkradiotoolbutton.c',
'gtkrange.c',
'gtkrbtree.c',
- 'gtkrecentchooser.c',
- 'gtkrecentchooserdefault.c',
- 'gtkrecentchooserdialog.c',
- 'gtkrecentchoosermenu.c',
- 'gtkrecentchooserwidget.c',
- 'gtkrecentfilter.c',
'gtkrecentmanager.c',
'gtkrender.c',
'gtkrenderbackground.c',
gtk_private_headers = gtk_private_type_headers + files([
'gtkrbtree.h',
- 'gtkrecentchooserutils.h',
])
gtk_public_headers = files([
'gtkradiomenuitem.h',
'gtkradiotoolbutton.h',
'gtkrange.h',
- 'gtkrecentchooser.h',
- 'gtkrecentchooserdialog.h',
- 'gtkrecentchoosermenu.h',
- 'gtkrecentchooserwidget.h',
- 'gtkrecentfilter.h',
'gtkrecentmanager.h',
'gtkrender.h',
'gtkrevealer.h',
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<interface domain="gtk40">
- <!-- interface-requires gtk+ 3.10 -->
- <object class="GtkListStore" id="recent_store">
- <columns>
- <!-- column-name uri -->
- <column type="gchararray"/>
- <!-- column-name display-name -->
- <column type="gchararray"/>
- <!-- column-name info -->
- <column type="GtkRecentInfo"/>
- </columns>
- </object>
- <template class="GtkRecentChooserDefault" parent="GtkBox">
- <property name="can-focus">False</property>
- <property name="orientation">vertical</property>
- <property name="spacing">6</property>
- <property name="expand">0</property>
- <child>
- <object class="GtkScrolledWindow" id="scrolledwindow">
- <property name="can-focus">1</property>
- <property name="hscrollbar-policy">never</property>
- <property name="shadow-type">in</property>
- <property name="vexpand">1</property>
- <child>
- <object class="GtkTreeView" id="recent_view">
- <property name="can-focus">1</property>
- <property name="has-tooltip">1</property>
- <property name="headers-visible">0</property>
- <property name="expand">1</property>
- <signal name="drag-begin" handler="recent_view_drag_begin_cb" swapped="no"/>
- <signal name="drag-data-get" handler="recent_view_drag_data_get_cb" swapped="no"/>
- <signal name="popup-menu" handler="recent_view_popup_menu_cb" swapped="no"/>
- <signal name="query-tooltip" handler="recent_view_query_tooltip_cb" swapped="no"/>
- <signal name="row-activated" handler="row_activated_cb" swapped="no"/>
- <child internal-child="selection">
- <object class="GtkTreeSelection" id="selection">
- <signal name="changed" handler="selection_changed_cb" swapped="no"/>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="icon_column">
- <property name="title">icon</property>
- <child>
- <object class="GtkCellRendererPixbuf" id="icon_renderer"/>
- </child>
- </object>
- </child>
- <child>
- <object class="GtkTreeViewColumn" id="meta_column">
- <property name="title">meta</property>
- <property name="expand">1</property>
- <child>
- <object class="GtkCellRendererText" id="meta_renderer">
- <property name="ellipsize">end</property>
- </object>
- </child>
- </object>
- </child>
- </object>
- </child>
- </object>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- <child>
- <object class="GtkBox" id="filter_combo_hbox">
- <property name="spacing">12</property>
- <child>
- <object class="GtkComboBoxText" id="filter_combo">
- <property name="tooltip-text" translatable="yes">Select which type of documents are shown</property>
- <property name="focus-on-click">0</property>
- <property name="entry-text-column">0</property>
- <property name="id-column">1</property>
- <signal name="changed" handler="filter_combo_changed_cb" swapped="no"/>
- </object>
- <packing>
- <property name="pack-type">end</property>
- </packing>
- </child>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- </template>
-</interface>
+++ /dev/null
-N_("Select which type of documents are shown");
gtk/gtkradiomenuitem.c
gtk/gtkradiotoolbutton.c
gtk/gtkrange.c
-gtk/gtkrecentchooser.c
-gtk/gtkrecentchooserdefault.c
-gtk/gtkrecentchoosermenu.c
gtk/gtkrecentmanager.c
gtk/gtkrevealer.c
gtk/gtkscalebutton.c
gtk/ui/gtkplacesview.ui
gtk/ui/gtkprintunixdialog.ui
gtk/ui/gtkprintunixdialog.ui.h
-gtk/ui/gtkrecentchooserdefault.ui
-gtk/ui/gtkrecentchooserdefault.ui.h
gtk/ui/gtksidebarrow.ui
gtk/ui/gtkvolumebutton.ui
gtk/ui/gtkvolumebutton.ui.h
['testoverlay'],
['testoverlaystyleclass'],
['testprint', ['testprintfileoperation.c']],
- ['testrecentchooser'],
- ['testrecentchoosermenu'],
['testscale'],
['testselectionmode'],
['testspinbutton'],
<property name="tab_fill">False</property>
</packing>
</child>
- <child>
- <object class="GtkRecentChooserWidget" id="recentchooser1">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="limit">20</property>
- </object>
- <packing>
- <property name="position">10</property>
- </packing>
- </child>
- <child type="tab">
- <object class="GtkLabel" id="label12">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label" translatable="yes">GtkRecentChooserDefault</property>
- </object>
- <packing>
- <property name="position">10</property>
- <property name="tab_fill">False</property>
- </packing>
- </child>
<child>
<object class="GtkColorButton" id="colorselection1">
<property name="visible">True</property>
+++ /dev/null
-/* testrecentchooser.c
- * Copyright (C) 2006 Emmanuele Bassi.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdlib.h>
-#include <time.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <gtk/gtk.h>
-
-#ifdef G_OS_WIN32
-# include <io.h>
-# define localtime_r(t,b) *(b) = localtime (t)
-# ifndef S_ISREG
-# define S_ISREG(m) ((m) & _S_IFREG)
-# endif
-#endif
-
-static void
-print_current_item (GtkRecentChooser *chooser)
-{
- gchar *uri;
-
- uri = gtk_recent_chooser_get_current_uri (chooser);
- g_print ("Current item changed :\n %s\n", uri ? uri : "null");
- g_free (uri);
-}
-
-static void
-print_selected (GtkRecentChooser *chooser)
-{
- gsize uris_len, i;
- gchar **uris = gtk_recent_chooser_get_uris (chooser, &uris_len);
-
- g_print ("Selection changed :\n");
- for (i = 0; i < uris_len; i++)
- g_print (" %s\n", uris[i]);
- g_print ("\n");
-
- g_strfreev (uris);
-}
-
-static void
-response_cb (GtkDialog *dialog,
- gint response_id)
-{
- if (response_id == GTK_RESPONSE_OK)
- {
- }
- else
- g_print ("Dialog was closed\n");
-
- gtk_main_quit ();
-}
-
-static void
-filter_changed (GtkRecentChooserDialog *dialog,
- gpointer data)
-{
- g_print ("recent filter changed\n");
-}
-
-static void
-notify_multiple_cb (GtkWidget *dialog,
- GParamSpec *pspec,
- GtkWidget *button)
-{
- gboolean multiple;
-
- multiple = gtk_recent_chooser_get_select_multiple (GTK_RECENT_CHOOSER (dialog));
-
- gtk_widget_set_sensitive (button, multiple);
-}
-
-static void
-kill_dependent (GtkWindow *win,
- GtkWidget *dep)
-{
- gtk_widget_destroy (dep);
- g_object_unref (dep);
-}
-
-int
-main (int argc,
- char *argv[])
-{
- GtkWidget *control_window;
- GtkWidget *vbbox;
- GtkWidget *button;
- GtkWidget *dialog;
- GtkRecentFilter *filter;
- gint i;
- gboolean multiple = FALSE;
-
- gtk_init ();
-
- /* to test rtl layout, set RTL=1 in the environment */
- if (g_getenv ("RTL"))
- gtk_widget_set_default_direction (GTK_TEXT_DIR_RTL);
-
- for (i = 1; i < argc; i++)
- {
- if (!strcmp ("--multiple", argv[i]))
- multiple = TRUE;
- }
-
- dialog = g_object_new (GTK_TYPE_RECENT_CHOOSER_DIALOG,
- "select-multiple", multiple,
- "show-tips", TRUE,
- "show-icons", TRUE,
- NULL);
- gtk_window_set_title (GTK_WINDOW (dialog), "Select a file");
- gtk_dialog_add_buttons (GTK_DIALOG (dialog),
- "_Cancel", GTK_RESPONSE_CANCEL,
- "_Open", GTK_RESPONSE_OK,
- NULL);
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
-
- g_signal_connect (dialog, "item-activated",
- G_CALLBACK (print_current_item), NULL);
- g_signal_connect (dialog, "selection-changed",
- G_CALLBACK (print_selected), NULL);
- g_signal_connect (dialog, "response",
- G_CALLBACK (response_cb), NULL);
-
- /* filters */
- filter = gtk_recent_filter_new ();
- gtk_recent_filter_set_name (filter, "All Files");
- gtk_recent_filter_add_pattern (filter, "*");
- gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
-
- filter = gtk_recent_filter_new ();
- gtk_recent_filter_set_name (filter, "Only PDF Files");
- gtk_recent_filter_add_mime_type (filter, "application/pdf");
- gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
-
- g_signal_connect (dialog, "notify::filter",
- G_CALLBACK (filter_changed), NULL);
-
- gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (dialog), filter);
-
- filter = gtk_recent_filter_new ();
- gtk_recent_filter_set_name (filter, "PNG and JPEG");
- gtk_recent_filter_add_mime_type (filter, "image/png");
- gtk_recent_filter_add_mime_type (filter, "image/jpeg");
- gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (dialog), filter);
-
- gtk_widget_show (dialog);
-
- control_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
-
- vbbox = gtk_button_box_new (GTK_ORIENTATION_VERTICAL);
- gtk_container_add (GTK_CONTAINER (control_window), vbbox);
-
- button = gtk_button_new_with_mnemonic ("_Select all");
- gtk_widget_set_sensitive (button, multiple);
- gtk_container_add (GTK_CONTAINER (vbbox), button);
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (gtk_recent_chooser_select_all), dialog);
- g_signal_connect (dialog, "notify::select-multiple",
- G_CALLBACK (notify_multiple_cb), button);
-
- button = gtk_button_new_with_mnemonic ("_Unselect all");
- gtk_container_add (GTK_CONTAINER (vbbox), button);
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (gtk_recent_chooser_unselect_all), dialog);
-
- gtk_widget_show (control_window);
-
- g_object_ref (control_window);
- g_signal_connect (dialog, "destroy",
- G_CALLBACK (kill_dependent), control_window);
-
- g_object_ref (dialog);
- gtk_main ();
- gtk_widget_destroy (dialog);
- g_object_unref (dialog);
-
- return 0;
-}
+++ /dev/null
-/* testrecentchoosermenu.c - Test GtkRecentChooserMenu
- * Copyright (C) 2007 Emmanuele Bassi <ebassi@gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "config.h"
-#include <gtk/gtk.h>
-
-static GtkRecentManager *manager = NULL;
-static GtkWidget *window = NULL;
-static GtkWidget *label = NULL;
-
-static void
-item_activated_cb (GtkRecentChooser *chooser,
- gpointer data)
-{
- GtkRecentInfo *info;
- GString *text;
- gchar *label_text;
-
- info = gtk_recent_chooser_get_current_item (chooser);
- if (!info)
- {
- g_warning ("Unable to retrieve the current item, aborting...");
- return;
- }
-
- text = g_string_new ("Selected recent item:\n");
- g_string_append_printf (text, " URI: %s\n",
- gtk_recent_info_get_uri (info));
- g_string_append_printf (text, " MIME Type: %s\n",
- gtk_recent_info_get_mime_type (info));
-
- label_text = g_string_free (text, FALSE);
- gtk_label_set_text (GTK_LABEL (label), label_text);
-
- gtk_recent_info_unref (info);
- g_free (label_text);
-}
-
-static GtkWidget *
-create_recent_chooser_menu (gint limit)
-{
- GtkWidget *menu;
- GtkRecentFilter *filter;
- GtkWidget *menuitem;
-
- menu = gtk_recent_chooser_menu_new_for_manager (manager);
-
- if (limit > 0)
- gtk_recent_chooser_set_limit (GTK_RECENT_CHOOSER (menu), limit);
- gtk_recent_chooser_set_local_only (GTK_RECENT_CHOOSER (menu), TRUE);
- gtk_recent_chooser_set_show_icons (GTK_RECENT_CHOOSER (menu), TRUE);
- gtk_recent_chooser_set_show_tips (GTK_RECENT_CHOOSER (menu), TRUE);
- gtk_recent_chooser_set_sort_type (GTK_RECENT_CHOOSER (menu),
- GTK_RECENT_SORT_MRU);
- gtk_recent_chooser_menu_set_show_numbers (GTK_RECENT_CHOOSER_MENU (menu),
- TRUE);
-
- filter = gtk_recent_filter_new ();
- gtk_recent_filter_set_name (filter, "Gedit files");
- gtk_recent_filter_add_application (filter, "gedit");
- gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (menu), filter);
- gtk_recent_chooser_set_filter (GTK_RECENT_CHOOSER (menu), filter);
-
- g_signal_connect (menu, "item-activated",
- G_CALLBACK (item_activated_cb),
- NULL);
-
- menuitem = gtk_separator_menu_item_new ();
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_label ("Test prepend");
- gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_label ("Test append");
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_mnemonic ("Clear");
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- return menu;
-}
-
-static GtkWidget *
-create_file_menu (GtkAccelGroup *accelgroup)
-{
- GtkWidget *menu;
- GtkWidget *menuitem;
- GtkWidget *recentmenu;
-
- menu = gtk_menu_new ();
-
- menuitem = gtk_menu_item_new_with_mnemonic ("_New");
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_mnemonic ("_Open");
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_mnemonic ("_Open Recent");
- recentmenu = create_recent_chooser_menu (-1);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), recentmenu);
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_separator_menu_item_new ();
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- menuitem = gtk_menu_item_new_with_mnemonic ("_Quit");
- gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
-
- return menu;
-}
-
-int
-main (int argc, char *argv[])
-{
- GtkWidget *box;
- GtkWidget *menubar;
- GtkWidget *menuitem;
- GtkWidget *menu;
- GtkWidget *button;
- GtkAccelGroup *accel_group;
-
- gtk_init ();
-
- manager = gtk_recent_manager_get_default ();
-
- window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size (GTK_WINDOW (window), -1, -1);
- gtk_window_set_title (GTK_WINDOW (window), "Recent Chooser Menu Test");
- g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
-
- accel_group = gtk_accel_group_new ();
- gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
-
- box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
- gtk_container_add (GTK_CONTAINER (window), box);
-
- menubar = gtk_menu_bar_new ();
- gtk_box_pack_start (GTK_BOX (box), menubar);
-
- menu = create_file_menu (accel_group);
- menuitem = gtk_menu_item_new_with_mnemonic ("_File");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
- gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
- menu = create_recent_chooser_menu (4);
- menuitem = gtk_menu_item_new_with_mnemonic ("_Recently Used");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
- gtk_menu_shell_append (GTK_MENU_SHELL (menubar), menuitem);
-
- label = gtk_label_new ("No recent item selected");
- gtk_box_pack_start (GTK_BOX (box), label);
-
- button = gtk_button_new_with_label ("Close");
- g_signal_connect_swapped (button, "clicked",
- G_CALLBACK (gtk_widget_destroy),
- window);
- gtk_box_pack_end (GTK_BOX (box), button);
- gtk_widget_set_can_default (button, TRUE);
- gtk_widget_grab_default (button);
-
- gtk_widget_show (window);
-
- gtk_main ();
-
- return 0;
-}
gtk_widget_destroy (widget);
}
-static void
-test_recent_chooser_widget_basic (void)
-{
- GtkWidget *widget;
-
- widget = gtk_recent_chooser_widget_new ();
- g_assert (GTK_IS_RECENT_CHOOSER_WIDGET (widget));
- gtk_widget_destroy (widget);
-}
-
#ifdef HAVE_UNIX_PRINT_WIDGETS
static void
test_page_setup_unix_dialog_basic (void)
g_test_add_func ("/Template/GtkFontButton/Basic", test_font_button_basic);
g_test_add_func ("/Template/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic);
g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic);
- g_test_add_func ("/Template/GtkRecentChooserWidget/Basic", test_recent_chooser_widget_basic);
#ifdef HAVE_UNIX_PRINT_WIDGETS
g_test_add_func ("/Template/UnixPrint/GtkPageSetupUnixDialog/Basic", test_page_setup_unix_dialog_basic);